Django框架的整合

Posted 高卓

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django框架的整合相关的知识,希望对你有一定的参考价值。

1.注册和配置django admin 后台管理页面

  在admin中执行如下配置

from django.contrib import admin
  
from app01 import  models
  
admin.site.register(models.UserType)
admin.site.register(models.UserInfo)
admin.site.register(models.UserGroup)
admin.site.register(models.Asset)

  设置数据表名称

class UserType(models.Model):
    name = models.CharField(max_length=50)
  
    class Meta:
        verbose_name = 用户类型
        verbose_name_plural = 用户类型

  打开表之后,设定默认显示,需要在model中作如下配置

class UserType(models.Model):
    name = models.CharField(max_length=50)
  
    def __unicode__(self):
        return self.name
from django.contrib import admin
  
from app01 import  models
  
class UserInfoAdmin(admin.ModelAdmin):
    list_display = (username, password, email)
  
  
admin.site.register(models.UserType)
admin.site.register(models.UserInfo,UserInfoAdmin)
admin.site.register(models.UserGroup)
admin.site.register(models.Asset)

  为数据表添加搜索功能

from django.contrib import admin
  
from app01 import  models
  
class UserInfoAdmin(admin.ModelAdmin):
    list_display = (username, password, email)
    search_fields = (username, email)
  
admin.site.register(models.UserType)
admin.site.register(models.UserInfo,UserInfoAdmin)
admin.site.register(models.UserGroup)
admin.site.register(models.Asset)

  添加快速过滤

from django.contrib import admin
  
from app01 import  models
  
class UserInfoAdmin(admin.ModelAdmin):
    list_display = (username, password, email)
    search_fields = (username, email)
    list_filter = (username, email)
      
  
  
admin.site.register(models.UserType)
admin.site.register(models.UserInfo,UserInfoAdmin)
admin.site.register(models.UserGroup)
admin.site.register(models.Asset)

 

以上是关于Django框架的整合的主要内容,如果未能解决你的问题,请参考以下文章

Django REST框架--认证和权限

Django框架的整合

Spring+SpringMVC+MyBatis+Maven框架整合

Django 从入门到忘记学习笔记

web框架底层原理;django介绍

如何在 Django Summernote 中显示编程片段的代码块?