On Mon, Oct 13, 2008 at 16:15, Christian Joergensen <[EMAIL PROTECTED]> wrote:
>
> Necmettin Begiter wrote:
> > Hello all,
> >
> > I have, say, 8 tables: Persons, works, phones, emails, addresses,
> > eaddresses, articles, books.
> >
> > Each one may have relationship with another one, like so:
> >
> > A person may have more than one work, phone, email, address, eaddress,
> > article and book.
> > A phone, email, address, eaddress, .. may be related to more than one
> > persons.
> >
> > So, here is a sample model:
> >
> > class Relations(models.Model):
> >     srctbl = models.CharField(max_length=2, choices=TBL_CHOICES)
> >     srcidx = models.IntegerField()
> >     tgttbl = models.CharField(max_length=2, choices=TBL_CHOICES)
> >     tgtidx = models.IntegerField()
> >
> > But there's a *slight* problem here. Possible values for *idx fields
> > must change when *tbl are changed, like so:
> >
> > If I select Person for srctbl, srcidx must contain names of possible
> > persons; if I select Phone for srctbl, srcidx must contain possible
> > phone numbers. And this is the same for tgt* fields. I have been looking
> > around Django Docs and references for a while now, but couldn't come
> > with a solution. IntegerField()s must actually be like ForeignKey(Person
> > or Phone or Email or Address or eAddress) .. Any ideas on how to achieve
> > this?
>
> Why aren't you using ManyToManyField's? It sounds like that's what
> you're trying to emulate ;)
>
> Regards,
>   Christian

AFAIK, ManyToManyFields' target table is pre-assigned, and cannot be
changed at runtime, is that not so? I mean, what I'm trying to achieve
is to create a ManyToMany relationship among differing tables.. Both
the source table and the target table are static when we talk about a
ManyToMany relationship. I need to be able to select the source and
target tables (models) at runtime. An example:

At the admin page (or my template, whatever), when I select Person as
the source table, SourceIdx / SourceName should be dynamically fetched
from the Person model. If I change it to Phone, this time members of
the Phone model should be listed. Am I missing something here, or is
this actually achievable through a ManyToMany relationship?

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

Reply via email to