Coding an inventory system, with polymorphic items and manageable item types

后端 未结 2 1238
旧巷少年郎
旧巷少年郎 2020-12-22 00:51

We currently have an inventory system for our employees. It contains laptops, phones, but also ergonomic chairs, fridges or software licenses ... So very different stuff tha

相关标签:
2条回答
  • 2020-12-22 01:09

    The Satchmo project is a django based e-commerce solution, which allows to manage different products and different options for a given products. Maybe you could find some inspiration in there.

    Another great tool for inheritance and polymorphism management is the Django model utils project, and the InheritanceManager it provides.

    I'm using in in production, to manage different kind of products (shirts, jackets, etc.), and it's really helpful.

    ** Edit **

    As requested, an example of a inheritance.

    class Product(models.Model):
        objects = InheritanceManager()
        client = models.ForeignKey('clients.Client')
        price = models.PositiveIntegerField()
    
    
    class Shirt(Product):
        color = …
    
    class Pants(Product):
        …
    
    products = Product.objects.all().select_subclasses()
    # products[0] can be a Shirt, and products[1] can be a Pants
    

    Note that I had to tweak a few things to make the code work with select_related, because of this issue.

    0 讨论(0)
  • 2020-12-22 01:20

    Ok ... at the time of the writing, Django is just not good with that.

    Schema-free databases such as mongodb are a good solution for this problem, and Django simply doesn't support those out of the box.

    So I gave up Django, and rewrote the whole thing in node.js with a mongodb database.

    0 讨论(0)
提交回复
热议问题