On Wed, 2008-11-19 at 13:35 -0800, Silvano wrote:
> Dear all
> 
> I'm completely stuck with the following problem.
> 
> What I'm trying to accomplish is: I have an app with the model
> "Project" and another model "Contacts". In "Contacts" I have a m2m
> field called "projects_involved" relating to the "Project" model which
> allows to select projects the contact is involved with.
> In my "Project" model I have some m2m fields like "client" and
> "collaborators" where I want to store a relation to some of the
> contacts. In the admin interface the user should be provided with
> contacts related to the actual "Project" only.
> 
> 
> class Contact(models.Model):
>     projects_involved = models.ManyToManyField('Project', blank=True)
> 
> 
> class Project(models.Model):
>     title = models.CharField(max_length=100)
>     client = models.ManyToManyField(Contact, related_name='client',
> blank=True)
>     collaborators = models.ManyToManyField(Contact,
> related_name='collaborators', blank=True)
> 
> 
> What I tried so far is to use a filter for constructing a choices list
> within the “Project” model.
> 
> related_contacts = Contact.objects.filter
> (projects_involved__title__starts_with=title)

But that isn't really what you have in your view. The lookup type in
Django is "startswith" (no underscore). If you wrote the above, it would
complain that "title" is not a joinable field.

> This gives me the following error in
> "/django/db/models/fields/__init__.py" line 102, in __cmp__
>     return cmp(self.creation_counter, other.creation_counter)
> AttributeError: 'str' object has no attribute 'creation_counter'

That error message is normally related to model creation, not filtering.
So what happens when you run "manage.py validate"? I suspect it will
report that same error. In which case, you've left something out of your
example code, because when I cut-and-paste exactly what you've written,
I don't see that error.

So run "manage.py validate" and make sure the same error is reported.
Then look at your code carefully to work out what is different between
what you have and what you've pasted here (start by pasting exactly what
you have here into a new project and verify it doesn't raise an error;
then slowly build up to what you have in the case that is causing the
error).

Regards,
Malcolm


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