2013/11/23 Harjot Mann <harjotmann1992@gmail.com>
On Sat, Nov 23, 2013 at 2:49 PM, Simone Dalla <simodalla@gmail.com> wrote:New Error.
> the correct code should be
>
> ...
> self.userprofile = UserProfile.objects.filter(user_id =1)
> self.userprofile.update(first_name = "Harjot")
> ...
> self.assertEqual(self.userprofile.user_id, 1)
Traceback (most recent call last):File "/home/harjot/Automation/../Automation/tcc/tests.py", line 22,
in test_profile
self.assertEqual(self.userprofile.user_id, 1)
AttributeError: 'QuerySet' object has no attribute 'user_id'
filter() [1] returns a QuerySet, if you want and are *absolutely sure* that your query will return a single object, use get() [2] instead, possibly with a try/catch block.
[1] https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.filter
[2] https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.get
[1] https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.filter
[2] https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.get
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5dYfNz0wvO6Twa2MtX-e5C38-Cm5Ewykn%3Dgvr3qd2E_ZGbbA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment