Monday, December 7, 2009

model design problem

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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate