2010-01-29 79 views
0

我正在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 

但是這些都沒有效果。

回答

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 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 
+0

完美,謝謝!對我來說,唯一的遺憾就是django繼續前進,縮小了MyProduct。所以我需要做product.myproduct(就像你寫的),而不是複製我的模型名稱product.MyProduct。 – fitzgeraldsteele 2010-02-02 19:28:45

相關問題