On Monday 12 June 2017 11:18:52 Akhi wrote: > def email_view(request, id): > course = get_object_or_404(CourseWare, pk=id) > user = UserProfile.objects.get(user__id=request.user.id) > myorder = MyOrder.objects.get_or_create(buyer=user, course=course)
Return value for get_or_create()[1] is tuple(obj: models.Model, created: bool). So your if check is useless as it is always true. But your method signature is incorrect as well. You're not supplying defaults. On top of that, you fetch the user profile twice and both cases can blow up if no profile exists. -- Melvyn Sopacua -------- [1] https://docs.djangoproject.com/en/1.11/ref/models/querysets/#get-or-create -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2197640.8K8CnvhUi6%40devstation. For more options, visit https://groups.google.com/d/optout.