Django DB Design - Maintaining common and historical data -


this more database design question specific django one.

we have small django app manage annual conference.

there models common each year of conference. example, workshops repeat each year, , use same rooms (seminar or accommodation rooms) well.

for these models, of fields common year year, whilst others vary.

for example, each accomodationroom has name, building, , features common year year. however, other things actual bed availability vary year year.

there requirement preserve historical data year year, want reduce redundant duplication if possible, , save having retype every year (e.g. names of rooms, sites, , features. likewise workshops)

my initial approach create accomodationroom stored common data, have example bedavailability stored transient year-to-year information, , provided link each year's conference. example:

class accommodationroom(models.model):     name = models.charfield(max_length=50)     site = models.foreignkey(site)     features = models.manytomanyfield(accommodationfeature, null=true, blank=true)  class bedavailability(models.model):     number_of_single_beds = models.integerfield()     number_of_double_beds = models.integerfield()     conference = models.foreignkey(conference)     accommodation_room = models.foreignkey(accommodationroom)  class conference(models.model):     year = models.charfield(max_length=4) # example 

however, way away 2 models, , have single accomodationroom model, contained everything, link directly conference model, , enforce uniqueness on accomodationroom.name , accomodationroom.conference.

class accommodationroom(models.model):     name = models.charfield(max_length=50)     site = models.foreignkey(site)     features = models.manytomanyfield(accommodationfeature, null=true, blank=true)     conference = models.foreignkey(conference)     number_of_single_beds = models.integerfield()     number_of_double_beds = models.integerfield()      class meta:         ordering = ['conference', 'name']         unique_together = (("name", "conference"),) 

or perhaps there's better way of doing haven't thought of? open suggestions here.

cheers, victor

a small modification first solution (i think better solution because more normalized second one)

class accommodationroom(models.model):     name = models.charfield(max_length=50)     site = models.foreignkey(site)     features = models.manytomanyfield(accommodationfeature, null=true, blank=true)     bed_availability = models.foreignkey(bedavailability)  class bedavailability(models.model):     number_of_single_beds = models.integerfield()     number_of_double_beds = models.integerfield()  class conference(models.model):     year = models.charfield(max_length=4) # example     accommodation = models.foreignkey(accommodationroom) 

using django admin backend, can first create bedavailability object specification of beds. can create accomodationroom object , associate bedavailability object it. can create conference object , associate accommodationroom object this.

in case need new set of bedavailability same accommodationroom year, can create new bedavailability object new specifications , link accommodationroom. not need re-enter accommodationroom data next conference if bedavailability specifications change.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -