Wednesday, September 22, 2010

Re: simple relationship difficult?

On Wed, Sep 22, 2010 at 7:11 AM, jayfee <josh.sarro@gmail.com> wrote:
hello, so i've been running into a problem across a handful of
frameworks, which is beginning to make me think i'm doing something
dumb :-) so hopefully someone will be kind enough to set me on the
right path. here's what i'm trying to do.

i am creating a system that will be used to categorize ideas,
information, people, places, etc. now one piece of information that i
want to have associated with basically everything is date information.
since it's not always possible to know exactly when something
happened, i'm implementing this as a range, including information
about how "sure" the user is.

to implement this, i've been creating a model for "DateRange",
including 4 pieces of scalar data (start date, end date, start
certainty, end certainty). and i've then been trying to include a
standard widget on all data entry pages (people, place, event, etc)
which is based on the DataRange model in a way that looks and acts
seemless. basically i want it to act just like it would if i simply
included those four pieces of information directly in each other model
(Place, Person, etc). that doesn't seem very DRY to me though :-)

now here's where i'm running into trouble over and over. the way i've
naturally wanted to to do this is to include a relationship going from
any given piece of data and pointing to a DateRange. for example, in
my Person model, i've included a birthday_Id, which is a foreign key
pointing to DateRange primary key. this is where things get tricky.

for some reason, none of the frameworks i've looked into, django
included, like this relationship. instead, they want me to have a
foreign key in DateRange pointing to each piece of data (Person,
Place, etc). this either means using a generic foreign key or having a
bunch of foreign keys in DateRange. or perhaps there's a better way?

You lost me with this last paragraph since you omitted what, exactly, leads you to say that none of the frameworks you ave looked at "like" this relationship, nor what leads you to say they "want" you to have a foreign key in the other direction.

Going back a couple of paragraphs, though, if you'd really like to operate as though these four pieces of information are included directly in other models, then I think you might be better off using model inheritance (http://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance) than a foreign key relationship. Have you looked into that way of doing this?

Karen
--
http://tracey.org/kmt/

--
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