0

模型.py

from django.db import models

class Students(models.Model):
    name=models.CharField(max_length=64),
    rollNo=models.IntegerField(),
    marks=models.IntegerField(),
    friends=models.CharField(max_length=64)

应用这些命令后;

py manage.py makemigrations 

py manage.py migrate 

0001_initial.py应该包含表的所有功能。但它只创建了 Id 和我提供的最后一个列名。

0001_initial.py

# Generated by Django 2.2.7 on 2020-01-06 08:57

从 django.db 导入迁移,模型

类迁移(migrations.Migration):

initial = True

dependencies = [
]

operations = [
    migrations.CreateModel(
        name='Students',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('friends', models.CharField(max_length=64)),
        ],
    ),
]

如何将所有列名存储在此文件中,以便我的表将反映在浏览器的管理页面上?

管理员.py

from django.contrib import admin
from testcase.models import Students

class StudentAdmin(admin.ModelAdmin):
    List_display=['id','name','rollNo','marks','friends']

admin.site.register(Students,StudentAdmin)
4

0 回答 0