I’m fairly new to Django / Channels so apologies if everything required isn’t being shown here. I’d be happy to provide further info if necessary.
Anyway, I’ve been working on an Ecommerce Website and am running into this error:
ValueError at /checkout/53469/
Cannot query "CartOrder object (21)": Must be "User" instance.
Here my checkout View:
@login_required
def checkout(request, oid):
order = CartOrder.objects.get(oid=oid)
order_items = CartOrderItems.objects.filter(order=order)
context = {
"order":order,
"order_items":order_items,
}
return render(request, "core/checkout.html", context)
Checkout URL
path('checkout/<oid>/', checkout, name="checkout"),
Checkout Model:
class CartOrder(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
full_name = models.CharField(max_length=100, null=True, blank=True)
email = models.CharField(max_length=100, null=True, blank=True)
phone = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=100, null=True, blank=True)
city = models.CharField(max_length=100, null=True, blank=True)
state = models.CharField(max_length=100, null=True, blank=True)
country = models.CharField(max_length=100, null=True, blank=True)
price = models.DecimalField(max_digits=12, decimal_places=2, default="0.00")
saved = models.DecimalField(max_digits=12, decimal_places=2, default="0.00")
shipping_method = models.CharField(max_length=100, null=True, blank=True)
traking_id = models.CharField(max_length=100, null=True, blank=True)
traking_website_address = models.CharField(max_length=100, null=True, blank=True)
paid_status = models.BooleanField(default=False, null=True, blank=True)
order_date = models.DateTimeField(auto_now_add=True, null=True, blank=True)
product_status = models.CharField(choices=STATUS_CHOICE, max_length=30, default="processing")
sku = ShortUUIDField(null=True, blank=True, length=5, prefix="SKU", max_length=20, alphabet="1234567890")
oid = ShortUUIDField(null=True, blank=True, length=5, max_length=20, alphabet="1234567890")
stripe_payment_intent = models.CharField(max_length=1000, null=True, blank=True)
#This class is for showing changed class name in Dashboard
class Meta:
verbose_name_plural = "Cart Order"
Checkout FronEnd:
{% for o in order_items %}
<div class="clo-lg-6 mb-2">
<div class="card" style="max-width:540px">
<div class="row g-0">
<div class="col-sm-4">
<img src="{{o.image}}" style="width:100%; height: 100%; object-fit:cover;" class="rounded-start" alt="Card image" />
</div>
<div class="col-sm-8">
<div class="card-body">
<h5 class="card-title">{{o.item}}</h5>
<p class="card-text fs-sm">Qty: {{o.qty}}</p>
<p class="card-text fs-sm">Price: ${{o.price}}</p>
<p class="card-text fs-sm">Total: ${{o.total}}</p>
</div>
</div>
</div>
</div>
</div>
{% endfor %}