Slot: gen name retrun by __str__() when save()

This name also used for itemize slots on admin screen

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura 2015-07-25 15:28:09 +09:00
parent a3c89ece12
commit c040257547

View file

@ -83,6 +83,7 @@ class SlotKind(models.Model):
@python_2_unicode_compatible
class Slot(models.Model):
name = models.CharField(max_length=100, editable=False)
day = models.ForeignKey(Day, verbose_name=_("Day"))
kind = models.ForeignKey(SlotKind, verbose_name=_("Kind"))
start = models.TimeField(verbose_name=_("Start"))
@ -145,9 +146,13 @@ class Slot(models.Model):
def rooms(self):
return Room.objects.filter(pk__in=self.slotroom_set.values("room"))
def __str__(self):
def save(self, *args, **kwargs):
roomlist = ' '.join(map(lambda r: r.__unicode__(), self.rooms))
return "%s %s (%s - %s) %s" % (self.day, self.kind, self.start, self.end, roomlist)
self.name = "%s %s (%s - %s) %s" % (self.day, self.kind, self.start, self.end, roomlist)
super(Slot, self).save(*args, **kwargs)
def __str__(self):
return self.name
class Meta:
ordering = ["day", "start", "end"]