'Object of type Modul is not JSON serializable while trying to set the value of another model in the session
i am trying to save the id of a created model in the session so i can update it later in anothe page, but the set function shows me an error
i am using request.session['ORDER'] = serializers.serialize('json', Order.objects.all()) right now but i also used request.session['ORDER'] = order.id, i got the same error
if form.is_valid():
if(form.cleaned_data['paymentmethod'] == "PayPal"):
print("Paypal choosed")
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
email = form.cleaned_data['email']
phone = form.cleaned_data['phone']
address = form.cleaned_data['address']
zipcode = form.cleaned_data['zipcode']
place = form.cleaned_data['place']
paymentmethod = 'pypnt'
order = checkout(request, first_name, last_name, email, address, zipcode, place, phone,
cart.get_total_cost(), paymentmethod)
print(order.id)
print(order)
request.session['ORDER'] = serializers.serialize('json', Order.objects.all())
return redirect('cart:process')
this is the Order Model
lass Order(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.CharField(max_length=100)
address = models.CharField(max_length=100)
zipcode = models.CharField(max_length=100)
place = models.CharField(max_length=100)
phone = models.CharField(max_length=100)
created_at = models.DateTimeField(auto_now_add=True)
paid_amount = models.DecimalField(max_digits=8, decimal_places=2)
vendors = models.ManyToManyField(Vendor, related_name='orders')
id = models.AutoField(primary_key=True)
class paymentmethod(models.TextChoices):
the error:
Internal Server Error: /de/cart/
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Product is not JSON serializable
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
