【发布时间】:2014-05-29 21:27:52
【问题描述】:
我有这些空的元组列表(DOC 和 COURSE),当产品被保存时,稍后会添加到他的特定列表中
CATEGORY = (
('DOC','DOCUMENTAZIONE'),
('COURSE','CORSO'),
)
class Product(BaseModel):
class Meta:
verbose_name=_('Prodotto')
verbose_name_plural=_('Prodotti')
name = models.CharField(_("Nome Prodotto"),max_length=1024, blank = False, null=True)
category = models.CharField(_("Categoria"),max_length=1024, blank = False, null=True,choices=CATEGORY)
def __unicode__(self):
return self.name
DOC = ()
COURSE = ()
try:
for product in Product.objects.all():
if product.category == 'DOC':
DOC = DOC + ((str(product.id), str(product.name.encode('utf-8'))),)
if product.category == 'COURSE':
COURSE = COURSE + ((str(product.id), str(product.name.encode('utf-8'))),)
except Exception as e:
print e
pass
class ProductOfferDoc(BaseModel):
class Meta:
verbose_name = _("Documentazione")
verbose_name_plural = _("Documentazioni")
product = models.CharField(max_length=1024, blank=False,null=False, choices=DOC)
number = models.IntegerField(_('Num.'), default=0, blank=True, null=True)
price = models.DecimalField(_('Prezzo'),max_digits=10, decimal_places=2,default=0.00,blank=True, null=True )
offer = models.ForeignKey(Offer, related_name='related_doc')
def __unicode__(self):
return self.product
class ProductOfferCourse(BaseModel):
class Meta:
verbose_name = _("Corso")
verbose_name_plural = _("Corsi")
product = models.CharField(max_length=1024, blank=False,null=False, choices=COURSE)
number = models.IntegerField(_('Num.'), default=0, blank=True, null=True)
price = models.DecimalField(_('Prezzo'),max_digits=10, decimal_places=2,default=0.00,blank=True, null=True )
offer = models.ForeignKey(Offer, related_name='related_course')
def __unicode__(self):
return self.product
我的问题是我需要显示可用的产品,但刚刚添加的新产品直到我重新启动服务器才会出现。 还有另一种方法可以做同样的事情吗?或者有添加产品时自动重启服务器的功能?
【问题讨论】:
-
对不起我之前的评论。我没有完全阅读这个问题。
标签: python django list tuples restart