satchmo中的自定义产品模板
问题描述:
我正在satchmo中实施一个商店。我使用产品模型中的模型继承创建了自定义产品MyProduct(如http://thisismedium.com/tech/satchmo-diaries-part-one/所示)。satchmo中的自定义产品模板
现在,我想有一个自定义的产品细节模板myProduct的,只有myProduct的。我试着在
/project/templates/product/product.html
创建一个模板,但它覆盖在店里所有产品的模板,而不仅仅是myProduct的。我也试过:
/project/templates/product/detail_myproduct.html
/project/templates/product/myproduct.html
但是这些都没有效果。
答
您的第一个猜测是你在正确的道路上: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
property on 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
完美,谢谢!对我来说,唯一的遗憾就是django继续前进,缩小了MyProduct。所以我需要做product.myproduct(就像你写的),而不是复制我的模型名称product.MyProduct。 – fitzgeraldsteele 2010-02-02 19:28:45