On Tue, Sep 30, 2008 at 4:52 AM, chris <[EMAIL PROTECTED]> wrote:

>
> Hi there,
>
> Just starting to use django, so forgive me if this has been answered
> before (a quick search at djanog-search did not turn up something
> useful).
> What I am trying to do is similar to this (from
> http://www.djangoproject.com/documentation/models/m2m_recursive/):
> <quote>
> from django.db import models
>
> class Person(models.Model):
>    name = models.CharField(max_length=20)
>    friends = models.ManyToManyField('self')
>    idols = models.ManyToManyField('self', symmetrical=False,
> related_name='stalkers')
>
> </quote>
> The difference is that I wanted to add additional information to the
> link, so need a separate table.  According to the documentation here
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany
> this is done with the additional through argument, so I get:
>
>    idols = models.ManyToManyField('self', symmetrical=False,
> related_name='stalkers' through="Relationship")
>
> and then define
>
> class Relationship(models.Model):
>    source = models.ForeignKey(Person, related_name="%
> (class)s_related_source")
>    target = models.ForeignKey(Person, related_name="%
> (class)s_related_target")
>    desc = models.CharField(max_length=20)
>
> However, when I do this, I get a runtime error complaining about the
> two foreign keys.
>
> I wonder how to solve this problem?
>
>
First, specifics on exactly when you get the runtime error and what it is
(posted traceback) would aid in getting you better responses faster.  The
traceback you eventually provided shows that the error is in the admin, when
you try to edit a Person which is apparently defined to have Relationships
edited inline -- yet you didn't mention admin or the admin definitions you
used in your initial report, making it rather difficult for anyone to make
the leap to what the real problem might be.

The problem is related to attempting to edit something inline that has more
than one ForeignKey to its parent.  When you set this up, you need to
specify which ForeignKey the admin is to use for the parent link, as
documented here:

http://docs.djangoproject.com/en/dev//ref/contrib/admin/#inlinemodeladmin-objects

under 'fk_name'.

If you correctly specify an 'fk_name' in your InlineModelAdmin class I
believe the error you are seeing will be fixed.

Karen

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