Custom product template in satchmo
I'm implementing a store in satchmo. I've created a custom product MyProduct by using model 开发者_如何学运维inheritance from the Product Model (as seen in http://thisismedium.com/tech/satchmo-diaries-part-one/).
Now I'd like to have a custom product detail template for MyProduct, and only MyProduct. I tried creating a template in
/project/templates/product/product.html
But that overrides the template for ALL products in the store, not just MyProduct. I also tried:
/project/templates/product/detail_myproduct.html
/project/templates/product/myproduct.html
But none of those seemed to work either.
You were on the right path with your first guess: templates/product/product.html.
If MyProduct is written like this:
class MyProduct(Product):
# ...
steele_level = model.IntegerField()
objects = ProductManager() # using this object manager is key!
And it is registered with the admin:
admin.site.regsiter(MyProduct)
Then you should be able to create a new MyProduct in the admin and then key off of a myproduct
property on the product in product/product.html:
{% if product.myproduct %}
This is a MyProduct with Steele Level: {{ product.myproduct.steele_level }}!
{% endif %}
Or if you prefer messing around in ./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
精彩评论