0
이것은 내 모델 및 뷰입니다. 나는 각 제품마다 30 % + 5 %, 30 % + 10 % 및 20 % + 5 %의 고정 할인을받는 3 가지 유형의 사용자가 있습니다. 내가 열심히 주어진 사용자에 대한 할인 된 가격을 반환 Ancillary
에 메서드를 추가 모델사용자 유형에 따라 쿼리 데이터를 변경하십시오.
from django.db import models
from django.core.urlresolvers import reverse
class Ancillary(models.Model):
product_code = models.CharField(max_length=60, null=True)
type = models.CharField(max_length=120, null=True)
product = models.CharField(max_length=120, null=True)
standard = models.CharField(max_length=120, null=True)
measurement = models.CharField(max_length=120, null=True)
brand = models.CharField(max_length=120, null=True)
price = models.Int(max_length=120, null=True)
class Meta:
verbose_name_plural = "Ancillaries"
def get_absolute_url(self):
return reverse('ancillaries')
def __unicode__(self):
return u'%s %s %s %s %s %s %s' % (self.id, self.product_code, self.type,
self.product, self.standard,
self.measurement, self.brand)
class AncillaryDetail(DetailView):
model = Ancillary
def get_context_data(self, **kwargs):
context = super(AncillaryDetail, self).get_context_data(**kwargs)
context['Ancillary_list'] = Ancillary.objects.all()
return context
은 많은 관계가있는 것입니까? – vvdect
@wdect : 사용자가 여러 유형을 가질 수 있는지 여부에 달려 있습니다. 당신이 말했던 것에서 나는 가정하지 않습니다. 어떤 경우에 그것은 단지 "ForeignKey"일 것입니다. –