Following is the dispatch function:

 def dispatch(self, request, *args, **kwargs):
        try:
            user_check_id = self.request.session.get("user_checkout_id")
            user_checkout = UserCheckout.objects.get(id=user_check_id)
        except UserCheckout.DoesNotExist:
            user_checkout = UserCheckout.objects.get(user=request.user)
        except:
            user_checkout = None

        obj = self.get_object()
        if obj.user == user_checkout and user_checkout is not None:
            return super(OrderDetail, self).dispatch(request, *args,
**kwargs)
        else:
            raise Http404

On line 27 color is red. Usually the error related to SimpleLazyObject
means that it's not able to grab the field with reference. I don't know
what to replace it with.

On Wed, Aug 31, 2016 at 5:31 AM, Andromeda Yelton <
[email protected]> wrote:

> I think the key line of the traceback is this -
> > File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
> >   27.             user_checkout = UserCheckout.objects.get(user=
> request.user)
>
> And the error is being thrown during your redirect to /orders/4/ at the
> end of the post. What does your orders/views.py look like around line 27?
>
> Unrelated to this error, but I'm also wondering what happens in
> CheckoutFinalView if the paymethod is CashOnDelivery or CreditCard -
> neither of those branches of your if statement actually return any sort of
> http response.
>
> On Wed, Aug 31, 2016 at 7:27 AM, Shazia Nusrat <[email protected]>
> wrote:
>
>> Hi I am having this error while I am trying to delete session and cart by
>> IDs after order fulfillment.
>>
>> carts/views.py
>>
>> class CheckoutFinalView(CartOrderMixin, View):
>>>     def post(self, request, *args, **kwargs):
>>>         order = self.get_order()
>>>         order_id = order.id
>>>         print order_id
>>>
>>>         pay_method = request.POST.get("paymethod")
>>>         print pay_method
>>>         order.save()
>>>
>>>         if request.POST.get('paymethod') == "CashOnDelivery":
>>>             order.mark_completed(order_id)
>>>             messages.success(request, "Thank you for your order")
>>>             del request.session["cart_id"]
>>>             del request.session["order_id"]
>>>         elif request.POST.get("paymethod") == 'CreditCard':
>>>             order.mark_completed(order_id)
>>>             messages.success(request, "Thank you for your order")
>>>             del request.session['order_id']
>>>             del request.session['cart_id']
>>>         else:
>>>             return redirect("order_detail", pk=order.pk)
>>>
>>
>> In my orders/models.py:
>>
>> order_id = models.CharField(max_length=20, null=True, blank=True)
>>     paymethod = models.CharField(max_length=16, choices=CHOICES,
>> default='CashOnDelivery')
>>
>>
>> My orders/views.py:
>>
>> class CashOnDelivery(FormView):
>>>     model = Order
>>>     form_class = PaymentForm
>>>     template_name = 'orders/payment_method.html'
>>>     success_url = '/checkout/final'
>>>
>>> My orders/forms.py:
>>
>> class PaymentForm(forms.ModelForm):
>>>     class Meta:
>>>         model = Order
>>>         fields = [
>>>             'paymethod'
>>>         ]
>>>
>>
>> My carts/checkout.html:
>>
>> {% extends 'base.html' %}
>>> {% load crispy_forms_tags %}
>>> {% block content %}
>>>
>>> <form method='POST' action="{% url 'checkout_final' %}">{% csrf_token %}
>>>  <!--<input type='hidden' name='payment_token' value='ABC' />-->
>>> <!--if method selected then cod should not display-->
>>>
>>>     {{ paymentform|crispy }}
>>>
>>>
>>>  <p><b><button type='submit'>Complete Order</button></b>
>>>     </p>
>>>
>>>     </form>
>>> {% endblock %}.
>>>
>>
>> Finally my complete traceback:
>>
>> > Traceback:
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\core\handlers\base.py"
>> in get_response
>> >   132.                     response = wrapped_callback(request,
>> *callback_args, **callback_kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\views\generic\base.py"
>> in view
>> >   71.             return self.dispatch(request, *args, **kwargs)
>> > File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
>> >   27.             user_checkout = UserCheckout.objects.get(user=
>> request.user)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\manager.py"
>> in manager_method
>> >   127.                 return getattr(self.get_queryset(), name)(*args,
>> **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in get
>> >   325.         clone = self.filter(*args, **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in filter
>> >   679.         return self._filter_or_exclude(False, *args, **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in _filter_or_exclude
>> >   697.             clone.query.add_q(Q(*args, **kwargs))
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
>> in add_q
>> >   1310.         clause, require_inner = self._add_q(where_part,
>> self.used_aliases)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
>> in _add_q
>> >   1338.                     allow_joins=allow_joins,
>> split_subq=split_subq,
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
>> in build_filter
>> >   1200.                                                     lookups,
>> value)
>> > File 
>> > "C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\related.py"
>> in get_lookup_constraint
>> >   1745.                     lookup_class(target.get_col(alias,
>> source), val), AND)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
>> in __init__
>> >   101.         self.rhs = self.get_prep_lookup()
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
>> in get_prep_lookup
>> >   139.         return 
>> > self.lhs.output_field.get_prep_lookup(self.lookup_name,
>> self.rhs)
>> > File 
>> > "C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\__init__.py"
>> in get_prep_lookup
>> >   727.             return self.get_prep_value(value)
>> > File 
>> > "C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\__init__.py"
>> in get_prep_value
>> >   985.         return int(value)
>> >
>> > Exception Type: TypeError at /orders/4/
>> > Exception Value: int() argument must be a string or a number, not
>> 'SimpleLazyObject'
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAD83tOxhgfQGucutTQ%2BFScou0VORFJPhSXUnhFei
>> wqUD2TyETg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAD83tOxhgfQGucutTQ%2BFScou0VORFJPhSXUnhFeiwqUD2TyETg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Andromeda Yelton
> Vice President/President-Elect, Library & Information Technology
> Association: http://www.lita.org
> http://andromedayelton.com
> @ThatAndromeda <http://twitter.com/ThatAndromeda>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CAFE1XCZx3Yd5P5iADGt9HKngh2XD7-seYH8PFDPvD7XB%3Det1Lw%
> 40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFE1XCZx3Yd5P5iADGt9HKngh2XD7-seYH8PFDPvD7XB%3Det1Lw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAD83tOzhXhfePOa-Qjpbc6Tvn1fzAJ9O8UjcVCMWAqdds_AVMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to