On zo, 2010-03-07 at 05:01 -0800, jorge.silva wrote:
> Hi there!
> 
> As far as I've read in the Django wiki this is a very common
> situation, yet I can't get it right....
> I've inherited a legacy database which I'm slowly trying to model in
> Django to benefit from the free Admin site. As long as I'm here I'm
> also trying to learn something ;)
> 
> My situation is as follows: I have two tables, 'Legislation' and
> 'Revoked'. The first contains data about a given legislation (name,
> date, etc....) while the later only contains two attributes
> (id_revoked, id_legislation) both of which are FK's to 'Legislation'.
> 
>
> If a Legislation appears in the Revoked relation by id_revoked it
> simply means it is Revoked by id_legislation. If on the contrary it is
> referenced by id_legislation it means it revokes id_revoked.
> 
> I'm trying to model this case in Django but I'm not getting it. Can
> you help me?
> Thanks in advance.

What your tables contain is what django calls a ManyToManyField. You
will need to specify a through model manually as you use different
column names than what django would use automatically. Something like
this should do the trick:

class Legislation(model.Model):
    revoked = models.ManyToManyField('self', through='Revoked')

class Revoked(models.Model):
    revoked = models.ForeignKey(Legislation, db_column='id_revoked')
    legislation = models.ForeignKey(Legislation, db_column='id_legislation)

-- 
Dennis K.

The universe tends towards maximum irony. Don't push it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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