I
I
ixotep2019-09-23 19:12:31
Django
ixotep, 2019-09-23 19:12:31

Django model for storing the plan and fact of the nomenclature, how to implement?

Good afternoon! The task is as follows:
There is a list of spare parts (not a reduced balance) that should be in the car, it is necessary to implement the database in such a way that different cars should have different (but may be the same) spare parts and different quantities.
I made a car model, nomenclature and unit of measure:

class Car(models.Model):
    driver = models.OneToOneField(User, on_delete=models.PROTECT, related_name='dr_excavator', blank=True,
                                  verbose_name='Учетная запись')
    title = models.CharField(verbose_name='Наименование автомобиля', max_length=20, blank=False)

    class Meta:
        verbose_name = 'Автомобиль'
        verbose_name_plural = 'Автомобили'

    def __str__(self):
        return self.title


class Units(models.Model):
    title = models.CharField(verbose_name='Ед.изм.', max_length=10, blank=False)

    class Meta:
        verbose_name = 'Ед.изм.'
        verbose_name_plural = 'Ед.изм.'

    def __str__(self):
        return self.title


class Nomenclature(models.Model):
    title = models.CharField(max_length=300, verbose_name='Наименование', blank=False)
    units = models.ForeignKey(Units, on_delete=models.PROTECT, related_name='nom_units', verbose_name='Ед.изм.')
  

    class Meta:
        verbose_name = 'Номенклатура'
        verbose_name_plural = 'Номенклатура'

    def __str__(self):
        return self.title

But how to merge into one table in which there will be a balance according to the plan, the balance after the fact and editing this from the admin panel I can’t understand. Kick in the right direction ... Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
szelga, 2019-09-24
@ixotep

as far as I understood the task, as a first approximation, I would do it like this:
1. add integer fields for balances according to the plan and after the fact to the stock model.
2. add a model for irreducible balances: by ForeignKey for Car and Nomenclature and an integer field for the value itself.
3. if necessary (which I'm not sure about), add a model for the actual balances assigned to the vehicle. the fields are the same as in the previous paragraph.
4. edit first in the Django admin panel, then write different Views in which to stuff the business logic (primarily restrictions) so that the exploiters and storekeepers don’t go into the admin panel in vain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question