inventory in Django

47 views
Skip to first unread message

Becka R.

unread,
Apr 8, 2016, 11:43:52 AM4/8/16
to Django users
Hi,

Sorry if this question seems basic, but I'm having trouble figuring out the best way to approach this on a high level. 

I'm at the beginning stages of building an ecommerce site,. Inventory changes regularly, and photos and descriptions need to be easy to update for my client. Is this an ajax problem or can this be done in views?  What are some elegant ways to approach this? I know this is a very common problem, which is great - direction would be helpful. 

Thank you.

Becka

Daniel Wilcox

unread,
Apr 8, 2016, 2:04:04 PM4/8/16
to django...@googlegroups.com

Hello, I don't know if there is an elegant way to approach this exactly... but here are some thoughts.  I typically move from more pages to fewer as I get messaging and more javascript working.  I recommend a similar approach so you have something working the whole time (tests help) and can get a feel for what is missing; maybe even bounce it off the client to see what they think.

The other thing is that is you know what you're client is using it for -- just imagine using the product for the required processes and what is needed at each step (read page) and draw the page on a piece of paper.  That'll help fill in your requirements.  Like, theoretically, "does the loading dock staff need to update quantities?"  OK what would that look like; 1) login, 2) create shipment 'object', 3) update product A through F while shipment X is selected.  Stuff like that.


First get your models worked out -- figure out all the fields you'll need for a product (this may be a client question).  You can put photos 'in' (I use this term loosely, it stores a file path) the product listing model itself to help associate the two.  Versatileimage does a great job -- and down the road you can make the site fully responsive quite easily as it supports resizing on the fly (and caches the result).

You have to think of how the data needs be stored to support the kind of queries you want.  Like for inventory can a quantity of a product be a discrete number?  It depends on the kind of product you're building -- for a store, probably unless it is huge, but for a warehouse, probably not.  In this case the decision is creating a 'Shipment' object or something of that sort with relations to products or just having an IntegerField on a product called 'quantity'.

Create some M->1 relations, or many to many if you need many categories per product, between products and categories, production and shipments or some other organizing principle.  You can always start with model views and then theme them up.

Creating a store that can be updated is about the same.  You'll basically do similar things to the admin console; for a product you'll have a form input per field and use the most natural one you can -- the admin console does a great job at this so you can look there for guidance on specific form field types (date pickers, file upload, multi-select inputs, etc).

Ajax is kinda an old way to refer to the strategy but yes you can add that at any point.  It might be helpful to define the pages that you want first and you can always make views that return XML, or JSON, later.  Unless of course you have a big ball of javascript already starting out in which case serializers are your friend but not always.

In any case once you start serializing I find it helps define some ToDict() methods on your models, or a top level abstract model for your app.  The method should do what it sounds like -- clean up the object for serialization (replace foreign keys with 'id' attributes, cast things to string as necessary, the serializer will complain you'll know).


A little ramble-y but hope that helps, cheers,

=D

jorr...@gmail.com

unread,
Apr 9, 2016, 10:04:45 AM4/9/16
to Django users
Have you looked into Django ecommerce packages that are already out there? They may fit most of your needs, and you could extend them where they don't.

https://www.djangopackages.com/grids/g/ecommerce/
Reply all
Reply to author
Forward
0 new messages