0

サッチモでストアを実装しています。Product Model からのモデル継承を使用してカスタム製品MyProductを作成しました ( http://thisismedium.com/tech/satchmo-diaries-part-one/を参照)。

ここで、 MyProduct のカスタム製品詳細テンプレートが必要で、 MyProductのみが必要です。でテンプレ作ってみた

/project/templates/product/product.html

ただし、これはMyProductだけでなく、ストア内のすべての製品のテンプレートをオーバーライドします。私も試しました:

/project/templates/product/detail_myproduct.html
/project/templates/product/myproduct.html

しかし、それらのどれも機能していないようでした。

4

1 に答える 1

1

あなたは最初の推測で正しい道を進んでいました:templates / product/product.html。

MyProductが次のように記述されている場合:

class MyProduct(Product):
    # ...
    steele_level = model.IntegerField()

    objects = ProductManager()  # using this object manager is key!

そしてそれは管理者に登録されています:

admin.site.regsiter(MyProduct)

myproduct次に、管理者で新しいMyProductを作成し、product/product.htmlの製品のプロパティをキーオフできるようになります。

{% if product.myproduct %}
    This is a MyProduct with Steele Level: {{ product.myproduct.steele_level }}!
{% endif %}

または、。/ manage.pyシェルをいじりたい場合は、次のようにします。

from project.models import MyProduct
from satchmo_store.shop.models import Product

for p in Product.objects.all():
    print p 
    if hasattr(p, 'myproduct'):
        print "  >>> That was a MyProduct with steele_level %s" % p.myproduct.steele_level
于 2010-01-30T04:06:02.490 に答える