Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

388
Views
How can I solve "ValueError - Cannot serialize"?

I have an error in my Django project. When I run the 'python manage.py makemigrations' command then comes the error.

ValueError: Cannot serialize: <django.db.models.query_utils.DeferredAttribute object at 0x000001B5A3078940>

File models.py

class Order(models.Model):
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    customer = models.ForeignKey(Customer,
                                 on_delete=models.CASCADE, null=True, blank=True)
    quntity = models.IntegerField(default=1)
    price = models.IntegerField(default=Product.price)
    address = models.CharField(max_length=200)
    phone = models.CharField(max_length=13)
    date = models.DateTimeField(auto_now=True)
    print(Product.price)

    def __str__(self) -> str:
        return self.product.name

File admin.py

from django.contrib import admin
from .models import Order

# Register your models here.


class OrderAdmin(admin.ModelAdmin):
    models = Order
    list_display =['product', 'customer', 'quntity', 'price', 'address', 'phone', 'date']

admin.site.register(Order, OrderAdmin)

Error page

Enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You cannot assign a default value to filed with default=Product.price

So change this line

price = models.IntegerField(default=Product.price)

to

price = models.IntegerField(default=0)

and if you want to set the order price from the product price, you can override the save() method

def save(self, *args, **kwargs):
    if self.product is not None:
        self.price = self.product.price

    super().save(*args, **kwargs)
over 4 years ago · Santiago Trujillo Report

0

I think that problem in the price attribute. You can use def save(), not default.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!