satchmo 中的自定义产品模板

发布于 2024-08-19 19:57:49 字数 581 浏览 2 评论 0 原文

我正在 satchmo 建立一家商店。我通过使用产品模型的模型继承创建了一个自定义产品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

但这些似乎都不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-08-26 19:57:49

您的第一个猜测是正确的: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 属性.html:

{% 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文