2010-01-29 7 views
0

satchmo에 상점을 구현하고 있습니다. 나는 http://thisismedium.com/tech/satchmo-diaries-part-one/에서 볼 수 있듯이 제품 모델의 모델 상속을 사용하여 맞춤 제품 MyProduct을 만들었습니다.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을 만들 수 있어야하고 키 오프 product/product.html에있는 myproduct 속성의 제품 :

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

감사합니다. 저에게있어서 유일한 장래성은 장고가 나아가 MyProduct를 소문자로 만들었다는 것입니다. 그래서 제품 모델을 복사하는 대신 product.myproduct (당신이 쓴 것처럼)를해야했습니다 .MyProduct. – fitzgeraldsteele

관련 문제