1
\$\begingroup\$

The usecase of my app I am trying to build is about Inventory Management System for a single company. I have attached a layout depicting what table or model should look like. I have designed the model the following way

enter image description here

class Office(models.Model):
    title = models.CharField(max_length=200, blank=True, null=True)
    sub_title = models.CharField(max_length=200, blank=True, null=True)
    name = models.CharField(max_length=200, blank=False, null=False)
    address = models.CharField(max_length=200, blank=True, null=True)
    phone = models.CharField(max_length=200, blank=True, null=True)
    email = models.EmailField(max_length=100, blank=True, null=True)

    class Meta:
        verbose_name = 'Office Setup'
        verbose_name_plural = 'Office Setup'

    def __str__(self):
        return self.name


class Department(models.Model):
    office = models.ForeignKey(Office, blank=False, null=False)
    name = models.CharField(max_length=200, blank=False, null=False)

    class Meta:
        verbose_name = 'Department'
        verbose_name_plural = 'Department'

    def __str__(self):
        return self.name


class DocumentNumbering(models.Model):
    office = models.ForeignKey(Office, blank=False, null=False)
    document = models.CharField(max_length=200, blank=False, null=False)
    start_number = models.PositiveIntegerField(
        default=0, blank=False, null=False)
    length = models.PositiveIntegerField(default=0, blank=False, null=False)

    class Meta:
        verbose_name = 'Document Numbering'
        verbose_name_plural = 'Document Numbering'

    def __str__(self):
        return self.document


class ItemUnit(models.Model):
    office = models.ForeignKey(Office, blank=False, null=False)
    name = models.CharField(max_length=200, blank=False, null=False)
    code = models.CharField(max_length=100, blank=True, null=True, unique=True)

    class Meta:
        verbose_name = 'Item Unit'
        verbose_name_plural = 'Items Unit'

    def __str__(self):
        return self.name

I just want to make ensure if this is the right way to do or not. Can anyone guide me on the relation part, please? I am not confident enough to tell if this is the way to model an app.

A lots of office = models.ForeignKey(Office, blank=False, null=False) in each table confused me.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.