Django Nested Serializers witj Foreign Field

I am trying to post this json request through postman

{   "name":"Someones order",
    "date_due": "2024-06-23T15:52:59Z",
    "customer":3,
    "orderItem":[{
        "item":1,
        "count":1
    }]
} 

I have implemented my models like so.

       class Item(models.Model):
            name = models.CharField(max_length=255) 
            price = models.DecimalField(max_digits=6, decimal_places=2)
            bakery = models.ForeignKey(Bakery,on_delete=models.CASCADE,related_name='items')
        
            def __str__(self):
                return f'{self.name}'
        
        class Order(models.Model):
        
            name = models.CharField(max_length=255) 
            bakery = models.ForeignKey(Bakery,on_delete=models.CASCADE,related_name='orders')
            customer = models.ForeignKey(Customer,on_delete=models.CASCADE,related_name='orders')
            date_created= models.DateTimeField(auto_now_add=True)
            date_due = models.DateTimeField()
            date_updated = models.DateTimeField(auto_now=True)
            #order_item = models.OneToOneField(OrderItem, on_delete=models.CASCADE,related_name='item_orderitems')
            def __str__(self):
                return f'{self.name}'
            
        class OrderItem(models.Model):
            bakery = models.ForeignKey(Bakery,on_delete=models.CASCADE,related_name='order_items')
            count = models.IntegerField()
            item = models.ForeignKey(Item, on_delete=models.CASCADE,related_name='item_orderitems')
            order = models.OneToOneField(Order, on_delete=models.CASCADE,related_name='orderitems')
            def __str__(self):
                return f'{self.name}'

Serializer is implemented as

class OrderItemCreateSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderItem
        fields = ['item','count']

class OrderCreateSerializer(serializers.ModelSerializer):
    
    orderItem=OrderItemCreateSerializer(many=True)
    class Meta:
        model = Order
        fields = ("name","date_due","customer","orderItem")
        
    def create(self, validated_data):
        print("create")
        print(validated_data)
        itemid=validated_data.pop("orderItem")
        print(itemid)
        bakery=self.context['request'].user.bakery
        customer=validated_data.pop("customer")
        
        print(customer)
        print("validated_data")
        print(validated_data)
        order=Order.objects.create(bakery=bakery,customer=customer,**validated_data)
        print("create 4")
        for items in itemid:
            print("create 5")
            OrderItem.objects.create(bakery=bakery,order=order,**items)
            print("create 6")
        print("returning")
        return order

When I make the post request i get

Got AttributeError when attempting to get a value for field orderItem on serializer OrderCreateSerializer.
The serializer field might be named incorrectly and not match any attribute or key on the Order instance.
Original exception text was: ‘Order’ object has no attribute ‘orderItem’.

I understand that Order model do not have a field pointing to orderitem but relation ship is rather reverse. But OrderCreateSerializer lists orderItem as a field.

I have implemented the same with a regular serializer instead of Modelserializer thinking that maybe it is complaining since it really is not part of the model.

But most important thing is that if you look at my print statements it prints “returning” and returns.

Should I implement the create method of the modelviewset and implement some of the logic there? would that help?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật