当我迁移django 2模型时,它制作的表没有任何问题,但是表的名称是这样的:nameofmodel_nameofmodel !!!例如,booking_booking !!! 这是我的代码:
from django.db import models
# Create your models here.
class Booking(models.Model):
user_id = models.CharField(max_length=50, null=True )
operator_id = models.CharField(max_length=50, null=True )
computed_net_price = models.CharField(max_length=50, null=True )
final_net_price = models.CharField(max_length=50, null=True )
payable_price = models.CharField(max_length=50, null=True )
booking_status = models.CharField(max_length=50, null=True )
guest_name = models.CharField(max_length=50, null=True )
guest_last_name = models.CharField(max_length=50, null=True )
guest_cellphone = models.CharField(max_length=50, null=True )
from_date = models.DateTimeField(max_length=50, null=True )
to_date = models.DateTimeField(max_length=50, null=True )
is_removed = models.IntegerField(null=True )
这是我的序列化器:
from rest_framework import serializers
from .models import Booking
class BookingSerializer(serializers.ModelSerializer):
class Meta:
model = Booking
fields =(
'user_id',
'computed_net_price',
'final_net_price',
'payable_price',
'booking_status',
'booking_status',
'guest_name',
'guest_last_name',
'guest_cellphone',
'guest_cellphone',
'guest_cellphone',
'operator_id',
'is_removed',
)
那么django的标准命名是什么?如果我想以其他方式使用它,而我做得正确还是不正确
答案 0 :(得分:1)
您可以这样:
class YourModel(models.Model):
# first_field = ....
# second_field = ....
class Meta:
db_table = 'table_name'
https://docs.djangoproject.com/en/2.2/topics/db/models/#meta-options