Files
ProdManager1/.ignore/models.py
2026-02-10 13:40:12 +03:00

40 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)