Tim Chase wrote: >> I'm in the process of turning telemeta [1] into a django >> application, and need dynamic model fields: we want to allow >> site administrators to easily add/remove "fields" to our main >> data structure, the MediaItem, which represents an audio/video >> resource. > > Our current app does something like this...our basic solution was > something like one of the two following ideas (depending on > whether particular categories should be consistent across labs, > such as "media" meaning the same thing in Lab1 and Lab2)
Actually the labs where just an example: one laboratory will have one installation of the application, and the dynamic fields will only apply within the scope of this installation. There's no such thing as consistency accross labs. > or the more simple "every lab has its own bag of categories that > don't relate to anybody else" (this is how we settled on it > because our clients rarely have much in common for these > category/value pairs): > > > class Lab(Model): > pass > class Category(Model): > lab = ForeignKey(Lab) > name = CharField(maxlength=40) > class Value(Model): > category = ForeignKey(Category) > value = CharField(maxlength=40) > class MediaItem(Model): > lab = ForeignKey(Lab) > values = ManyToMany(Values) Well, that's what I almost did... with support for enumerations (some fields must only accept predetermined values): class MediaItem(models.Model): "Describe an audio/video item with metadata" title = models.CharField(maxlength=250) author = models.CharField(maxlength=250) def get_dynamic_properties(self): "Retrieve dynamic properties associated with a given media item" [...] class MediaItemPropertyDefinition(models.Model): "Define a media item dynamic property" TYPE_CHOICES = (('text', 'Text'), ('enumeration', 'Enumeration')) name = models.CharField(maxlength=64) type = models.CharField(maxlength=64, choices = TYPE_CHOICES) class MediaItemPropertyEnumerationItem(models.Model): "Define a possible value for media item dynamic enumeration properties" definition = models.ForeignKey(MediaItemPropertyDefinition, core=True) name = models.CharField(maxlength=250) class MediaItemProperty(models.Model): "Associate a value to a media item dynamic property" definition = models.ForeignKey(MediaItemPropertyDefinition, core=True) media_item = models.ForeignKey(MediaItem) value = models.CharField(maxlength=250) enum_item = models.ForeignKey(MediaItemPropertyEnumerationItem, null=True) However, watching the MySQL verbose log, I realized that retrieving properties as well as their definitions (and enumeration values) to properly display an detail view or edition form execute a _lot_ of SQL queries, when this could be achieved with one or two joins... I'm afraid it won't scale. Or does your "ManyToMany(Values)" field helps for optimization? May I expect any help from manipulators, managers, query sets (all of these are still a bit obscure to me) ? Regards, -- Olivier - http://www.samalyse.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---