I have these empty lists of tuples (DOC and COURSE) and when a product is saved, later is added into his specific list
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
My problem is that i need to display avaible products, but the new product just added doesn't appear until i restart the server. There is another way to do the same thing? Or exist a function to restart the server automatically when a product is added?