Merge pull request #107 from miurahr/gen_str_name_when_save

slot: generate __unicode__ name when save()
This commit is contained in:
Patrick Altman 2015-12-28 10:50:32 -06:00
commit 46a10b9e3a

View file

@ -82,6 +82,7 @@ class SlotKind(models.Model):
@python_2_unicode_compatible @python_2_unicode_compatible
class Slot(models.Model): class Slot(models.Model):
name = models.CharField(max_length=100, editable=False)
day = models.ForeignKey(Day, verbose_name=_("Day")) day = models.ForeignKey(Day, verbose_name=_("Day"))
kind = models.ForeignKey(SlotKind, verbose_name=_("Kind")) kind = models.ForeignKey(SlotKind, verbose_name=_("Kind"))
start = models.TimeField(verbose_name=_("Start")) start = models.TimeField(verbose_name=_("Start"))
@ -149,9 +150,13 @@ class Slot(models.Model):
def rooms(self): def rooms(self):
return Room.objects.filter(pk__in=self.slotroom_set.values("room")) 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)) 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: class Meta:
ordering = ["day", "start", "end"] ordering = ["day", "start", "end"]