Issue
So, I have two models, Order
and Orders
, and for each item that I have in my session(cart)
Im creating an Order_object(saving in database) and after each item is saved I want to do a check for every Order
telling which ones are not a foreign key in Orders
, if not, create an Orders_object than add each Order
who is not a foreign key of Orders
And I wish that each Orders
have multiple Order
Models.py
class Order(models.Model):
----fields---
class Orders(models.Model):
order = models.ManyToManyField(Order)
----other fields ------
Solution
order_all = Order.objects.all()
orders_all = Orders.objects.all()
for order_object in order_all:
the_order_object_is_not_fk_in_orders = True
for orders in orders_all:
for orders_order_object in orders.order.all():
if orders_order_object == order_object:
the_order_object_is_not_fk_in_orders = False
break
if the_order_object_is_not_fk_in_orders == True:
#do something
Answered By - Kaynan Kaynan Felipe Rodrigues
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.