I’m encountering an error when testing this code with Postman. Can you help me identify the cause? “AssertionError at /POST_Create_NewInvoiceBuy/
("Creating a ModelSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = '__all__' to the Create_NewInvoiceBuy_serializers serializer.",) "
“I want to store invoice data in three tables that have a one-to-many relationship. However, I keep getting the following error:
I’ve tried various approaches, but I’m still unable to identify the source of the issue. Can anyone provide guidance?”
the code is :
# -----------models products---------------------
class Tbl_Products (models.Model):
Code_product=models.IntegerField(blank=False,null=False)
Name_product=models.CharField(max_length=30, blank=True , null=True)
Unit_counting=models.CharField(max_length=20)# واحد شمارش
Amount=models.IntegerField(blank=True,null=False)
Unit_price=models.IntegerField(blank=True , null=True)
#-------------tables --------
class Tbl_ListAccounting (models.Model):
Code_Account=models.IntegerField(default=100 , blank=False, null=False)
Name_Account=models.CharField(max_length=50 , blank=True , null=True)
Type_Account=models.CharField(max_length=50 , blank=True , null=True)
class Tbl_purches (models.Model):
Custom_id = models.CharField(max_length=10, primary_key=True)
Code_Invoice_purches=models.IntegerField(default=100 , blank=False, null=False)
Create_DateInvoice=models.DateField(auto_now_add=True,blank=False, null=False)
Due_date=models.DateField(auto_now_add=True, blank=False, null=False)
Name_customer=models.ForeignKey(Tbl_Customers,on_delete=models.PROTECT, blank=False, null=False)
class Tbl_Detail_invoice_purches(models.Model):
# Code_product=models.ForeignKey(Tbl_Products, on_delete =models.CASCADE)
Name_product= models.CharField(max_length=20 , blank=False, null=True)
Unit_Counting=models.CharField(max_length=100 ,blank=False ,null=True)
Amount_product=models.DecimalField(max_digits=13,decimal_places=2 )
Unit_price=models.DecimalField(max_digits=13,decimal_places=2)
Total_price=models.DecimalField(max_digits=13,decimal_places=2 )
ID_Tbl_detail=models.ForeignKey(Tbl_purches, on_delete=models.CASCADE,blank=False,null=False )
#--------------------------------serializer create newinvoice -----------
class Detail_NewInvoice_Serializers(serializers.ModelSerializer):
class Meta :
model=Tbl_Detail_invoice_purches
fields= '__all__'
class Create_NewInvoiceBuy_serializers (serializers.ModelSerializer):
Detail_invoice_purches =Detail_NewInvoice_Serializers(read_only=True)
class Meta :
model=Tbl_purches
fileds=['Custom_id','Code_Invoice_purches','Create_DateInvoice','Name_customer','Due_date','Detail_invoice_purches']
def create (self,validated_data) :
Detail_invoice_data=validated_data.pop( 'Detail_invoice_purches')
purches=Tbl_purches.objects.create(**validated_data)
for item in Detail_invoice_data:
Tbl_Detail_invoice_purches.objects.create(ID_Tbl_detail=purches ,**item)
return purches
and the data is {
"Create_DateInvoice": "2025/04/03",
"Name_customer": "hemo",
"Due_date": "2026/04/03",
"Detail_invoice_purches": [
{
"Code_product": "88888",
"Name_product": "Cheksns_morgh",
"Unit_Counting": "kg",
"Amount_product": "1500",
"Unit_price": "58000",
"Total_price": "870000000"
}
]
}