Kevin
Kevin

Reputation: 4351

Trying to make a small inventory app in Django

I am trying to make a small inventory app in a Django app. I want to be able to see the stock on hand, where it is (between two places and all together), purchase to add to inventory, and sell to reduce inventory. Tracking sales would be nice. So all in all, there are about five things I would like to do. To track the location, I was thinking of listing warehouse one as 1 and two as 2, and could query WHERE field = 1, but if I have the same product in two places, I would run into an issue. I also don't know the best way to approach it. Reading through post here, I see some people saying to just track sales, and total them in a flat db, others to remove from the db, but that would lead to discrepancies. This is my model.py so far, just really stabbing at the dark here, looking for some guidance.

from django.db import models

class Product(models.Model):
    product_ID = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    type = (
        ('WHT' , 'White Wine'),
        ('RED' , 'Red Wine'),
        ('SPRT', 'Spirits'),
        ('BR'  , 'Beer'),
    )
    size = (
        ('12' , '12oz'),
        ('16'  , '16oz'),
        ('375' , '375mL'),
        ('750' , '750mL'),
        ('1' , '1L'),
    )
    amount_per_case = models.IntegerField()
    warehouse = (
            (1 , 'One'),
            (2 , 'Two'),
    )
    on_hand = models.IntegerField() 

class Store(models.Model):
    store_ID = models.IntegerField(primary_key=True)
    store_name = models.CharField()
    store_type = (
            ('Supermarket', 'Supermarket'),
            ('Liquor Store', 'Liquor Store'),
    )
    store_address = models.CharField()
    store_phone = models.CharField()
    store_contact = models.CharField()

class Vendor(models.Model):
    vendor_ID = models.IntegerField(primary_key=True)
    vendor_name = models.CharField()
    vendor_address = models.CharField()
    vendor_phone = models.CharField()
    vendor_contact = models.CharField()

class Sale(models.Model):
    sale_date = models.DateField()
    sale_product = models.ForeignKey(Product)

Upvotes: 1

Views: 4291

Answers (1)

acjay
acjay

Reputation: 36531

You should make a Warehouse model and create a many-to-many relationship between Product and Warehouse, using the through option to specify another model to hold relationship details called something like WarehouseProduct, in which you store the counts. See this section of the docs, and the following section.

P.S. You can do much the same thing to associate sales with particular stores, which seems to me to be something that would probably be of interest to you, as well.

Upvotes: 1

Related Questions