Django satchmo中的自定义产品模板

Django satchmo中的自定义产品模板,django,templates,satchmo,Django,Templates,Satchmo,我正在satchmo建立一个商店。我使用产品模型的模型继承创建了一个自定义产品MyProduct(如中所示) 现在我想为MyProduct定制一个产品详细信息模板,并且只为MyProduct。我尝试在中创建一个模板 /project/templates/product/product.html 但这会覆盖商店中所有产品的模板,而不仅仅是MyProduct。我还尝试: /project/templates/product/detail_myproduct.html /project/templa

我正在satchmo建立一个商店。我使用产品模型的模型继承创建了一个自定义产品MyProduct(如中所示)

现在我想为MyProduct定制一个产品详细信息模板,并且只为MyProduct。我尝试在中创建一个模板

/project/templates/product/product.html
但这会覆盖商店中所有产品的模板,而不仅仅是MyProduct。我还尝试:

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

但是这些似乎都不起作用。

你的第一个猜测是正确的:templates/product/product.html

如果我的产品是这样写的:

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

    objects = ProductManager()  # using this object manager is key!
并在管理员处注册:

admin.site.regsiter(MyProduct)
然后,您应该能够在管理中创建一个新的MyProduct,然后在product/product.html中关闭产品上的
MyProduct
属性:

{% if product.myproduct %}
    This is a MyProduct with Steele Level: {{ product.myproduct.steele_level }}!
{% endif %}
或者如果您更喜欢在./manage.py shell中混日子:

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

太好了,谢谢!对我来说,唯一的问题是django继续并将MyProduct小写。所以我需要做product.myproduct(就像你写的那样),而不是复制我的模型名product.myproduct。