Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango-TastyPie reverse indirect foreign key
    text
    copied!<p>I have the following models in my Django app where An <strong>Order</strong> is related to a <strong>Cart</strong>, a <strong>cartItem</strong> is related to a <strong>Cart</strong> and a <strong>product</strong>. Now in my tastypie api when i GET an order i also want to get all the products associated with the order's cart.</p> <pre><code>class Order(models.Model): objects = OrderManager() order_number = models.CharField(max_length=20, editable=False,unique=True, default=get_unique_order_number) user = models.ForeignKey(User, blank=True, null=True) cart = models.ForeignKey(Cart, blank=True, null=True) ... class Cart(models.Model): user = models.ForeignKey(User) is_check_out = models.BooleanField(default=False) ... class CartItem(models.Model): objects = CartItemManager() cart = models.ForeignKey(Cart) product = models.ForeignKey(Product) ... class CartRelatedResource(ModelResource): class Meta: queryset = Cart.objects.all() allowed_methods = ['get'] excludes = ['is_check_out', 'session', 'creation_date', 'modification_date'] include_resource_uri = False authentication = SessionAuthentication() class OrderResource(ModelResource): cart = fields.ForeignKey(CartRelatedResource, 'cart',full=True) class Meta: queryset = Order.objects.all() resource_name = 'order' fields = ['cart_id','delivery_time','shipping_address_id','billing_address_id', 'tip','phone','delivery_instructions'] include_resource_uri = False allowed_methods = ['post','get'] authentication = SessionAuthentication() authorization = OrderAuthorization() </code></pre> <p>I don't think using ToManyField will work in this case. Will it? What is the best way to achieve what i want?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload