I am designing a week-based menu application. I am wondering if I should just do this:
class MenuWeek(models.Model):
sunday = OneToOneField("MenuDay")
monday = OneToOneField("MenuDay")
#etc through Saturday
class MenuDay(models.Model):
# some stuff here, but not a foreign key to MenuWeek
instead of this:
class MenuDay(models.Model):
week = ForeignKey("MenuWeek") # (with no OneToOne's defined in MenuWeek)
Is the first way a good way to implement a short “fixed-length” list relationship between parent and child or should i just stick with ForeignKey in the MenuDay and enforcing length through forms validation? I’m thinking the administration may be cleaner, the first way, where its clear which day of a week you are editing.
Thanks
I would never use your first option. You’ll end up repeating yourself all over the place to run a particular section of code for each weekday. The second option will result in much nicer code down the road.