Доброго времени суток!
При создании CRM столкнулся с такой проблемой - при создании новой записи, вылазит эта ошибка
Как избавится от этой ошибки?
models.py
from django.db import models
PAPER_CHOICE = [
('1', 'TOP'),
('2', 'PLG'),
('3', 'PP'),
('4', 'ЭКО'),
]
PRIORITY_CHOICE = [
('1', 'Высокий'),
('2', 'Средний'),
('3', 'Низкий'),
]
STATUS_CHOICE = [
('1', 'Новый'),
('2', 'В работе'),
('3', 'Завершён'),
]
class Order(models.Model):
number = models.CharField(max_length=20, verbose_name='Номер заказа', unique=True)
paper = models.CharField(max_length=20, choices=PAPER_CHOICE, verbose_name='Бумага')
density = models.IntegerField(verbose_name='Плотность')
container = models.IntegerField(verbose_name='Контейнер')
bobbin_width = models.IntegerField(default=1530, verbose_name='Ширина бобины')
priority = models.CharField(max_length=20, choices=PRIORITY_CHOICE, verbose_name='Приоритет')
status = models.CharField(max_length=20, choices=STATUS_CHOICE, verbose_name='Статус')
time_create = models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')
time_update = models.DateTimeField(auto_now=True, verbose_name='Дата обновления')
def __str__(self):
return self.number
class Meta:
verbose_name = "Заказ"
verbose_name_plural = "Заказы"
ordering = ['number']
serializers.py
from rest_framework import serializers
from orders.models import Order
class OrderSerializer(serializers.ModelSerializer):
paper = serializers.CharField(source='get_paper_display', label='Бумага')
priority = serializers.CharField(source='get_priority_display', label='Приоритет')
status = serializers.CharField(source='get_status_display', label='Статус')
class Meta:
model = Order
fields = ('number', 'paper', 'density', 'container', 'bobbin_width', 'priority', 'status',)
views.py
from rest_framework import generics, viewsets
from .models import Order
from .serializers import OrderSerializer
class OrderViewSet(viewsets.ModelViewSet):
queryset = Order.objects.all()
serializer_class = OrderSerializer
urls.py
from django.urls import path, include
from rest_framework import routers
from .views import OrderViewSet
router = routers.DefaultRouter()
router.register(r'orders', OrderViewSet)
urlpatterns = [
path('api/v1/', include(router.urls)),
]