model的meta 设定

花生与浊酒 / 2023-07-19 / 原文

 
from django.db import models

class Post(models.Model):
    no = models.IntegerField()
    name = models.CharField(max_length=128)

    class Meta:
        # 昇順
        ordering = ["no"]
        # 降順
        # ordering = ['-no']
        # テーブル名をmypostに変更
        db_table = 'mypost'
        # 管理サイト上のモデルの表記方法を変更
        verbose_name = 'ポスト'  # 単数形
        # verbose_name_plural = 'ポスト群'  # 複数形