我有一个使用Django Rest Framework制作的基本CRUD应用程序,该应用程序从用户那里获取交货编号,并让他们输入任何DeliveryIssue
模型以简单模式形式使用的交货问题
我想添加一种方法,一旦在表单上输入了交货编号,它就可以查找Customer Name
模型中出现的Delivery Date
和DeliveryInfo
并在提交前先形成表格。然后将该信息与DeliveryIssue
模型一起保存。
class DeliveryIssue(models.Model):
class Meta:
db_table = 'APP_Delivery_Issue'
delivery = models.PositiveIntegerField(db_column = 'Delivery')
issue_category = models.CharField(max_length=200, db_column = 'Issue Category')
issue = models.CharField(max_length=200, db_column = 'Issue')
detail = models.TextField(db_column = 'Detail')
created_at = models.DateTimeField(auto_now_add=True, db_column = 'Create Datetime')
updated_at = models.DateTimeField(auto_now=True, db_column = 'Update Datetime')
class DeliveryInfo(models.Model):
detail = models.CharField(db_column='Delivery', max_length=50, blank=True, null=False, primary_key=True)
customer = models.CharField(db_column='Customer', max_length=250, blank=True, null=True)
delivery_date = models.DateField(db_column='Delivery Date', blank=True, null=True)
class Meta:
managed = False
db_table = 'INFO_DELIVERY'
我已阅读过pre_save,但不确定如何在此处使用它。这是serializers.py
文件
from rest_framework import serializers
from .models import DeliveryIssue
class DeliveryIssueSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = DeliveryIssue
fields = '__all__'