I'm getting obsessed! I have an API (TatstyPie) which saves a product. Every time this resource is saved I assign stock or rise an error if their is no stock.
*get and allocate some stock:* stock = Stock.objects.filter(availability="Available", product=product)[:1].get() *check we have stock:* except Stock.DoesNotExist: raise CustomBadRequest( code="stock", message="No stock left" ) *if ok, assign stock to product:* instance.stock = stock stock.allocate() So far I have moved this logic around so many times, but where should it really be happening in my Django project? Opinions very much welcome. Thanks 1) product *pre_save* - this works really well but validation looks odd here! 2) product *model save()* - again validation looks odd here! 3) product *model manager *- this seems bad as I'm referencing the stock model in product manager. 4) *views* - I end up repeating the save validation and code looks really bad, also I have to do it again for API and normal views 5) *tastypie recourse* - just as bad as views I think. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f561aea1-a788-4093-94ea-af5c1a6d0dbb%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.