I am creating a Django application that must store multiple selected dates to have an event. The very first factor that found mind was build the big event model:
class Event(models.Model): title = models.CharField(max_length=200) creator = models.ForeignKey(User) modified = models.DateTimeField(auto_now=True, auto_now_add=False) created = models.DateTimeField(auto_now=False, auto_now_add=True) def __unicode__(self): return self.title class Meta: ordering = ('title',)
Build another table of EventDates:
class EventDate(models.Model): event = models.ForeignKey(Event) date = models.DateField() modified = models.DateTimeField(auto_now=True, auto_now_add=False) created = models.DateTimeField(auto_now=False, auto_now_add=True) def __unicode__(self): return "%s / %s" % (self.event, self.date) class Meta: ordering = ('created',)
But is the easiest way? It is possible to better carrying out alternative, just like a comma separated string?
The easiest way is the one which best serves your reasons. There's no built-in comma separated area in Django, but it is simple to roll your personal one - the issue is if this sounds like what you actually need.
For instance - if you want to filter occasions according to their dates, I am unsure the way you could easily do that with your comma separated area, however i can clearly observe how you could do this this together with your current approach:
-- so unless of course you specify your planned usage pattern, I do not think there's an over-all answer.