0

これが私のモデルとビューです。すべての製品でそれぞれ 30% + 5%、30% + 10%、20% + 5% の固定割引を受ける 3 種類のユーザーがいます。モデルの各ユーザーの価格をハードコーディングせずにそれを行う方法はありますか

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   
4

1 に答える 1