Hacker News new | ask | show | jobs
by mrfusion 4518 days ago
Maybe you guys can help me apply this to an actual Django project I'm working on.

So I made an "Order" model to track orders. But now I have to add a lot of logic regarding things such as what can be ordered together, and which users can order what.

Where you keep that logic? It seems to make sense to me to put it right in the model, no?

1 comments

Personally I would make models a package rather than just a module (since you sy you have a lot of order related logic). I would create one or more modules in this package, presumably one of those for orders.

Then I would actually create the base logic which clearly belongs to one Order instance as methods on the Order class.

If you have something like "can x and y and (...)" be ordered together I would make an unbound function in your orders module which takes an iterable (Lists etc.) of Orders and works on it.

Note that I am by no means a Django guru or something like that.