Understood, thanks Paul. I missed this section from documentation :)

--Tirta 
-----Original Message-----
From: Paul van der Linden <p...@soulbase.nl>

Date: Wed, 24 Dec 2008 11:09:25 
To: <django-users@googlegroups.com>
Subject: Re: Model with 2 foreignkey to User



Hi,
just do as the error is telling you.

    created_by  = models.ForeignKey(User, related_name='createdBy')
    assigned_to = models.ForeignKey(User, related_name='assignedBy')

or something like that. That works.

Tirta K. Untario wrote:
> Hi all,
>
> I'm developing a simple todo list. I use Django Auth for handling 
> authentication. This is my models.py
>
> from django.contrib.auth.models import User
> class Item(models.Model):
>     project     = models.ForeignKey(Project)
>     category    = models.ForeignKey(Category)
>     title       = models.CharField(max_length=250, unique=True) 
>     priority    = models.IntegerField(choices=PRIORITY_CHOICES, default=2) 
>     completed   = models.BooleanField(default=False) 
>     created_at  = models.DateTimeField(default=datetime.datetime.now) 
>     created_by  = models.ForeignKey(User)
>     assigned_to = models.ForeignKey(User)
>
> I have 2 fields from Item model that I want to relate with User model: 
> 'created_by' and 'assigned_to'. This is the error message when I try to 
> syncdb:
>
> Error: One or more models did not validate:
> todo.item: Accessor for field 'created_by' clashes with related field 
> 'User.item_set'. Add a related_name argument to the definition for 
> 'created_by'.
> todo.item: Accessor for field 'assigned_to' clashes with related field 
> 'User.item_set'. Add a related_name argument to the definition for 
> 'assigned_to'.
>
> If I use only 1 foreignkey, it works without error, i.e:  created_by  = 
> models.ForeignKey(User) without  assigned_to  = models.ForeignKey(User)
>
> Can anyone help me to solve this problem? TIA.
>
> --Tirta
>
>
> >
>   




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

Reply via email to