Первая попытка модельки
This commit is contained in:
39
.ignore/models.py
Normal file
39
.ignore/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from django.db import models
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
from django.utils.text import slugify
|
||||
|
||||
TYPE_CHOICES = (
|
||||
('Лист', 'Лист'),
|
||||
('Труба', 'Труба'),
|
||||
('Круг', 'Круг'),
|
||||
('Уголок', 'Уголок'),
|
||||
('Профиль', 'Профиль'),
|
||||
('Плита', 'Плита'),
|
||||
('Швеллер', 'Швеллер'),
|
||||
('Ребро', 'Ребро'),
|
||||
('Тонкий', 'Тонкий'),
|
||||
('Толстый', 'Толстый'),
|
||||
)
|
||||
|
||||
class Part(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
decimal_number = models.CharField(max_length=50, unique=True)
|
||||
type = models.CharField(max_length=50, choices=TYPE_CHOICES)
|
||||
thickness = models.FloatField(null=True, blank=True)
|
||||
length = models.FloatField(null=True, blank=True)
|
||||
weight = models.FloatField(null=True, blank=True)
|
||||
cut_length = models.FloatField(null=True, blank=True)
|
||||
number_of_punches = models.IntegerField(null=True, blank=True)
|
||||
slug = models.SlugField(unique=True, max_length=255)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.slug = slugify(f"{self.name}-{self.decimal_number}")
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.decimal_number})"
|
||||
|
||||
class ProductStructure(MPTTModel):
|
||||
item = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='structures')
|
||||
quantity = models.FloatField()
|
||||
parent = TreeForeignKey('self', on_delete=models.CASCADE)
|
||||
Reference in New Issue
Block a user