Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to put Product to Cart via tasytpie API?
    primarykey
    data
    text
    <p>Let's assume we have these models, original project differs but this would be the common task:</p> <pre><code>class Cart(models.Model): owner = models.ForeignKey(User) products = models.ManyToManyField(Product, symmetrical=False) class Product(models.Model): title = models.CharField(max_length="255") description = models.TextField() </code></pre> <p>Now I want to put a Product into the Cart via the api.</p> <p>I started like this:</p> <pre><code>class CartResource(ModelResource): products = fields.ManyToManyField(ProductResource, 'products', full=True) def override_urls(self): return [ url(r"^(?P&lt;resource_name&gt;%s)/product/(?P&lt;prodcut_id&gt;\w[\w/-]*)/$" % (self._meta.resource_name), self.wrap_view('dispatch_detail_product'), name="api_dispatch_detail_product"), ] def dispatch_detail_product(.....): # A get is not useful or is it? # A post could put a product into the cart # A put (preferred) could put a product in the cart # A delete could delete a product from the cart class Meta: queryset = Product.objects.all() authentication = MyBasicAuthentication() authorization = DjangoAuthorization() list_allowed_methods = ['get'] detail_allowed_methods = ['get', 'put', 'delete'] def obj_update(self, bundle, request=None, **kwargs): return super(PrivateSpaceResource, self).obj_create(bundle, request, owner=request.user) def apply_authorization_limits(self, request, object_list): if len(object_list.filter(owner=request.user)) == 0: Cart.objects.create(owner=request.user) return object_list.filter(owner=request.user) </code></pre> <p>But I'm not sure what to do. Compared to django, tastypie is absolute developer-unfriendly. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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