2016-10-24 6 views
0

は、私自身の証券を選択するための戦略と価格を宣言した私はカタログのアプリで作成したカスタムモデルクラスをインポートする必要があったまで、すべてがうまく働きました。 私の目標は、価格選択戦略のためにこのカスタムモデルにアクセスすることでした。oscar.partnerアプリの戦略モジュールにモデルを正しくインポートする方法は? <a href="http://django-oscar.readthedocs.io/en/releases-1.1/topics/prices_and_availability.html" rel="nofollow">http://django-oscar.readthedocs.io/en/releases-1.1/topics/prices_and_availability.html</a></p> <p>で説明したように、私が定義した

私はこのようなモデルをインポートしようとした /apps/partner/strategy

CountrySpecificProductInformation = get_model('catalogue', 'CountrySpecificProductInformation') 

この呼び出しはモデルではない登録例外発生します

File "/home/matyas/virtenvs/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 250, in get_model 
    return apps.get_registered_model(app_label, model_name) 
    File "/home/matyas/virtenvs/oscar/local/lib/python2.7/site-packages/django/apps/registry.py", line 260, in get_registered_model 
    "Model '%s.%s' not registered." % (app_label, model_name)) 
LookupError: Model 'catalogue.CountrySpecificProductInformation' not registered. 

を自分のインストール済みのアプリケーションの設定は次のようになります。

INSTALLED_APPS = ['...'] + 
oscar.get_core_apps(['apps.catalogue', 'apps.promotions', 'apps.dashboard', 
          'apps.dashboard.catalogue', 'apps.partner', 'apps.payment', 'apps.dashboard.partners', 
          'apps.shipping', 'apps.checkout', 'apps.search']) 

私は使用していますdjango-oscar 1.3Django 1.9.9

答えて

0

Oscarには、電子商取引ソリューションのアプリケーションの一部を上書きできるようにするために必要な独自のインポートシステムがあります。

戦略クラスは、サーバーの起動時に早期にインポートされ、一部のモデルはまだ登録されていません。

解決策は、インポートセクションでモジュールの上部にないモジュールをインポートすることでしたが、モデルが必要な方法でのみインストールされました。 (select_stockrecord法であった私の場合:インポートget_classをoscar.core.loadingから

、get_model
CountrySpecificProductInformation = get_model( 'カタログ'、 'CountrySpecificProductInformation')

def select_stockrecord(self, product): 
    CountrySpecificProductInformation = get_model('catalogue', 'CountrySpecificProductInformation') 
    Country = get_model('catalogue', 'Country') 

これは完璧な解決策ではありませんが、私は未処理のSQLクエリを直接データベースに書き込むのではなく、この方法をお勧めします。

関連する問題

 関連する問題