There is no need to write anything at all in the Country table It seems to me, there is an attempt to write to the Country table, but it should be added to the table associated with the order. And I get the errror: A country named Country already exists The create method doesn't even start working. Validated_data = (id=specialization_id)Ĭreate_order_transfer_money(user, currency, price, order) Specialization_id = validated_data.pop('specialization_id') If check_customer_balance(customer=user, currency=currency, price=price):
Specialization_id = serializers.IntegerField()įields = Ĭountry = CountryOrderSerializer(many=True)Ĭountry_data = validated_data.pop('country', ) Serializers.py class OrderCreateSerializer(serializers.ModelSerializer): Region = models.ForeignKey(Region, on_delete=models.PROTECT, related_name='countries') Phone_code = models.CharField(max_length=15, blank=True, null=True)įlag = models.FileField(upload_to='flags/', null=True, blank=True) Name = models.CharField(max_length=150, unique=True) Specialization = models.ForeignKey(to='categories.Specialization', on_delete=models.PROTECT, related_name='order_specializations')Ĭountry = models.ManyToManyField(Country, related_name='countries', blank=True)Ĭustomer = models.ForeignKey(User,verbose_name=_("Заказчик"), on_delete=models.CASCADE, related_name='order_customers') Price = models.DecimalField(max_digits=10, decimal_places=2, default=0, blank=True, null=True)Ĭreated_at = models.DateTimeField(auto_now_add=True)
I have models: class Order(models.Model): I have an order model, when creating an entry in the create method of the serializer, I try to add a country to the manytomany field, but I get an error: A country named Country already exists