Hello Biola, When you do a update in a queryset, the objects of the Session that already instantiated need to be updated. If you do in your test: self.assertEqual(Session.objects.get(id=result.id).price, Decimal('700')) The assertion will be ok
2014-11-10 8:21 GMT-02:00 Biola Oyeniyi <gbo...@gmail.com>: > I have atttempted updating a model based on using the update() method as > described in the docs > https://docs.djangoproject.com/en/dev/ref/models/querysets/ , > I have used both sqlite and postgres but still end up with the model not > being updated. > > My code is shown below. > > def create_session(self, email='devito@gmailcom', > date=datetime.datetime.now(), > duration=datetime.timedelta(hours=1)): > new_user = UserFactory(email=email) > sf = TutorSessionFactory(tutor_with_skill=self.ts, buyer=new_user, > date=date,duration=duration) > return sf > > > def test_can_update_ehen_udated(self): > result = self.create_session() > *Session.objects.filter(id=result.id > <http://result.id>).update(price=Decimal('700'))* > self.assertEqual(result.price,Decimal('700')) > > > And the error message > > Failure > Traceback (most recent call last): > File "C:\Python27\Lib\unittest\case.py", line 329, in run > testMethod() > File > "F:\work-projects\python\django-projects\Tuteria\tuteria\tutor_sessions\tests\test_model.py", > line 24, in test_can_update_ehen_udated > self.assertEqual(result.price,Decimal('700')) > File "C:\Python27\Lib\unittest\case.py", line 513, in assertEqual > assertion_func(first, second, msg=msg) > File "C:\Python27\Lib\unittest\case.py", line 506, in _baseAssertEqual > raise self.failureException(msg) > AssertionError: Decimal(500) != Decimal('700') > > Any confirmation on the above error would be appreciated > > -- > 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+unsubscr...@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/83c6c0e3-592e-4357-8556-797eff6e261d%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/83c6c0e3-592e-4357-8556-797eff6e261d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- []`s Ricardo L. Dani http://about.me/ricardodani -- 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+unsubscr...@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/CAEq3mejytVqAJDtLdeO_sBmk08OERVF9mwfpfgm2%3D8GpdrJF7Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.