Первая попытка модельки
This commit is contained in:
58
.ignore/views.py
Normal file
58
.ignore/views.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
from django.http import JsonResponse
|
||||
from .models import Part, ProductStructure
|
||||
from .filters import PartFilter
|
||||
from django.contrib import admin
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.html import format_html
|
||||
|
||||
class PartList(View):
|
||||
def get(self, request):
|
||||
filter = PartFilter(request.GET, queryset=Part.objects.all())
|
||||
return JsonResponse({
|
||||
'results': [self.part_to_json(part) for part in filter.qs],
|
||||
'filters': filter.filters.items()
|
||||
})
|
||||
|
||||
def part_to_json(self, part):
|
||||
return {
|
||||
'id': part.id,
|
||||
'name': part.name,
|
||||
'decimal_number': part.decimal_number,
|
||||
'type': part.get_type_display(),
|
||||
'thickness': part.thickness,
|
||||
'length': part.length,
|
||||
'weight': part.weight,
|
||||
'cut_length': part.cut_length,
|
||||
'number_of_punches': part.number_of_punches,
|
||||
'slug': part.slug
|
||||
}
|
||||
|
||||
class PartAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'decimal_number', 'type', 'thickness', 'weight')
|
||||
search_fields = ('name', 'decimal_number')
|
||||
list_filter = ('type',)
|
||||
|
||||
inlines = [
|
||||
ProductionOperationInline
|
||||
]
|
||||
|
||||
class ProductionOperationInline(admin.TabularInline):
|
||||
model = ProductionOperation
|
||||
extra = 1
|
||||
|
||||
class ProductionOperation(models.Model):
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='operations')
|
||||
operation_type = models.CharField(max_length=50, choices=[
|
||||
('Лазер', 'Лазер'),
|
||||
('Сварка', 'Сварка'),
|
||||
('Покраска', 'Покраска'),
|
||||
('Обработка', 'Обработка'),
|
||||
])
|
||||
time = models.FloatField()
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.part.name} - {self.operation_type}"
|
||||
Reference in New Issue
Block a user