class OrderReserve models Model handbookmodel models OneToOneField Han

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class OrderReserve(models.Model):
handbookmodel = models.OneToOneField(HandBookModel, verbose_name=u"Модель")
reserving = models.ManyToManyField('Reserving', verbose_name=u"Заявки на резеревирование")
all_quantity_reserve = models.IntegerField(u'Общее количества резерва', null=True, editable=False, default=0)
class Meta:
constraints = (
("check_all_quantity_reserve", Check(all_quantity_reserve__gte = 0)),
)
def save(self):
super(OrderReserve, self).save()
self.all_quantity_reserve = sum(map(lambda x: x.quantity_reserve,self.reserving.all()))
return super(OrderReserve, self).save()
def was_published_today(self):
return self.date_pub.date() == datetime.date.today()
def __unicode__(self):
return '%d' % (self.all_quantity_reserve)