Hello All, I recently extended my User, with a User profile called GenericUserProfile, and it has a many-to-many field called farms (code below). Now all I want to do was add a "farm" to this farms field in the GenericUserProfile.
But when I try doing that using the django python shell I get error - "AttributeError: 'QuerySet' object has no attribute 'get_profile'". I'd really appreciate if someone could point out what I'm doing incorrectly and what is the correct approach. The documentation says that get_profile() is created when the profile is present and I checked the database and it shows an entry in "genericuserprofile" table corresponding to the "user" who is registered. Code - # The User profile which extends fields for User class GenericUserProfile(models.Model): user = models.ForeignKey(User) #other fields here farms = models.ManyToManyField(Farm) confirmation_code = models.CharField(max_length=200, unique=True) is_active = models.BooleanField() create_dt = models.DateTimeField(auto_now_add=True) modify_dt = models.DateTimeField(auto_now_add=True) def __str__(self): return "%s's profile" % self.user def create_user_profile(sender, instance, created, **kwargs): if created: profile,created = GenericUserProfile.objects.get_or_create (user=instance) post_save.connect(create_user_profile, sender=User) # The Farm model, A user can have many farms, and farms can have many owners, hence many-to-many class Farm(models.Model): farm_id = models.AutoField(primary_key=True) is_owner = models.BooleanField() #### I try this in the django python shell, I want to add the farm to the "farms" field in GenericUserProfile. Hence trying to get the profile first. >>> f1 = Farm(farm_id=None, is_owner=True) >>> f1.save() >>> c1 = User.objects.filter(email__iexact="x...@xyz.com") >>> c1.get_profile Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'QuerySet' object has no attribute 'get_profile' --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---