0

when i migrate my django 2 models it makes tables without any problem but the name of table is like this :‌nameofmodel_nameofmodel !!! so for example booking_booking !!! here is my code :

    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 )

and here is my serializer :

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',
         )

so what is the standard naming of django and what if i want to have it in a different way and i am doing correctly or not

1
  • 1
    It is formed like "yourappname_yourtablename". Table name is saved in django in this way. I think your model is standard. djangobook.com/mdj2-models Commented Jun 23, 2019 at 12:26

1 Answer 1

1

You can make like that:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.