I'm not clear on what you need to store, so I'll assume that you have individual data to store for each port of each type, and it is unrelated to data stored for another instance of the same or a different product.
What comes to mind is that there is a "Product" model and a "Port" model (or if red and green ports carry different fields, both a "RedPort" and a "GreenPort" model). Ports have a foreign key relationship on Products. Now an assortment of Port instances can be assigned to a Product instance. Django will created an accessor (or accessors) on the Product model for obtaining a query set of the Port instances associated with a given Product instance. (If you want separate RedPort and GreenPort models, but they share a lot of behaviours and/or fields, you may want to look at Django's abstract base class mechanism, but it takes a bit to get right, in my experience.) On Mon, Dec 7, 2009 at 10:12 AM, Dan <daniel.goert...@gmail.com> wrote: > I am relatively new to django and relational databases, and need some > Model advice. > > I have a family of network products each with a different combination > of ports.. I will call them red ports and green ports. For example, > product A will have its own Model and could have 2 red ports and 1 > green port. Product B is similar, but has only 3 green ports. > My current approach is to use an abstract base Model, and then create > Models for products A and B that contain all needed fields, for > example: > > class A(basemodel): > Port1_redfield1 = ... > Port1_redfield2 = ... > ... > Port2_redfield1 = ... > Port2_redfield2 = ... > ... > > > Yuck, not very DRY at all. I also tried to create a red port Model > and green port Model and use one to one fields to connect them to > products. The problem with this is that I could not figure out how to > encapsulate the ports; I always had to worry about creating, linking > and deleting port objects when dealing with products. Not acceptable. > > I also thought about other tricks like generating my models.py file > from a generator program, and dynamic insertion of attributes into > existing classes. I really would rather not go there. > > So, my question: Is there a nice DRY way to get the kind of > structured composition that I want? > > Side question: Is there another python ORM that could address my need > better? > > Thanks, > Dan. > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.