I've recently stumbled over a problem whose solution I can't find. I
have a class with two fields that use the built-in User class (from
django.contrib.auth.models) in a many-to-many relationship. However,
when I try to access or modify those fields, django throws an error
message. My class declaration is:
class Organization(models.Model):
name = models.CharField(maxlength=40)
sponsor = models.ManyToManyField(User,
related_name='sponsored_orgs', null=True)
members = models.ManyToManyField(User,
related_name='orgs_belonged_to', null=True)
test = models.ForeignKey(User)
The following code:
o = Organization()
o.sponsor
causes an error after the second line:
Traceback (most recent call last):
File "<console>", line 1, in ?
File
"/usr/local/lib/python2.4/site-packages/django/db/models/fields/related.py",
line 405, in __get__
target_col_name=qn(self.field.m2m_reverse_name())
File
"/usr/local/lib/python2.4/site-packages/django/db/models/fields/related.py",
line 244, in __init__
raise ValueError("%r instance needs to have a primary key value
before a many-to-many relationship can be used." % model)
ValueError: <class 'django.contrib.auth.models.User'> instance needs to
have a primary key value before a many-to-many relationship can be used.
I'm not sure what causes this. The test ForeignKey causes no problems.
Even if I do o.sponsor.any.random.text(), the same error occurs. Has
anyone else seen this issue? I would greatly appreciate any help. Thanks,
Nick Fishman
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---