Reference article:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/ (the Django admin site)
List_display
models.py
from django.db import modelsfrom django.utils.html import format_htmlclass Author (models. Model): name = models. Charfield (max_length=30) email = models. Emailfield (blank=true) website = models. Urlfield (blank=true) def namecase (self): return self.name.upper () namecase.short_description = ' name Case ' def __unicode__ (self): return u '%s ' % (self.name) def colored_name (self) : return format_html (' <span style= ' color:red ">{ } {} </span><b>{}</b ', self.website, self.name, Self.email) colored_name.allow_tags = true def my _property (self): return self.name + ' ' + self.email my_property.short_description = ' Full spell of the name ' full_name = property (my_property)
admin.py
From Django.contrib import adminfrom dragonball.models import authorclass authoradmin (admin. Modeladmin): List_display = (' Full_name ', ' upper_case_name ', ' colored_name ', ' namecase ', ' __str__ ', ' email ', ' website ') def upper_case_name (self, obj): Return ("%s-to-%s"% (Obj.name.upper (), obj.email)) Upper_case_name.short_de scription = ' Name & email '
Front-end Display:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/DD/wKioL1S_Q2rC6ugNAAIHVPqAngs720.jpg "title=" a1.jpg "alt=" Wkiol1s_q2rc6ugnaaihvpqangs720.jpg "/>
Inlinemodeladmin
Ability to edit another models on a models page, for example, to add a blog to a author page.
Two sub-Methods:
Tabularinline
Stackedinline
admin.py
From Django.contrib import adminfrom dragonball.models import blogclass bloginline (admin. Tabularinline): Model = Blogclass authoradmin (admin. Modeladmin): Inlines = [Bloginline,]
Front-end Display:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/E2/wKiom1S_Zz_D3GcIAAIcxpLmotk243.jpg "title=" a1.jpg "alt=" Wkiom1s_zz_d3gciaaicxplmotk243.jpg "/>
The Django Admin site List_display