當數據模型建立完成時,接下來需要將模型裡的數據展示出來,而且是通過模板這種類型進行顯示
class Article(models.Model):
created_time = models.DateTimeField(auto_now_add=True)
last_updated_time = models.DateTimeField(auto_now=True)
class Article(models.Model):
author = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=1)
class Article(models.Model):
is_deleted = models.BooleanField(default=False)
class Article(models.Model):
readed_num = models.IntegerField(default=0)
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Article(models.Model):
title = models.CharField(max_length=30)
content = models.TextField()
created_time = models.DateTimeField(auto_now_add=True)
last_updated_time = models.DateTimeField(auto_now=True)
author = models.ForeignKey(User, on_delete=models.DO_NOTHING, default=1)
is_deleted = models.BooleanField(default=False)
readed_num = models.IntegerField(default=0)
def __str__(self):
return "<Article: %s>" % self.title
python manage.py makemigrations
python manage.py migrate
from django.contrib import admin
from .models import Article
# Register your models here.
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
list_display = ("id", "title", "content", "author", "is_deleted", "created_time", "last_updated_time")
ordering = ("-id",)
Study Python There are many di
Python Automatic code extracti