LOADING

Follow me

Django 1.6Admin(二)
十二月 6, 2013|IT

Django 1.6Admin(二)



1

from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
    date_hierarchy = 'pub_date'


将所date字段放到列表最上端


2.


ModelAdmin.actions_on_top

ModelAdmin.actions_on_bottom

设置action在顶端还是底部


3.

exclude = ('birth_date',)


除去某个字段,不显示


4.

fields = ('url', 'title', 'content')


列出字段,一个一行


5.

class FlatPageAdmin(admin.ModelAdmin):
    fields = (('url', 'title'), 'content')


列出字段 一个小括号一行



7.

class FlatPageAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('url', 'title', 'content', 'sites')
        }),
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('enable_comments', 'registration_required', 'template_name')
        }),
    )


设置分类给字段归组



8.

{
'classes': ('wide', 'extrapretty'),
}


为字段集添加css



9


filter_vertical和filter_horizontal


前面的是垂直多选择,后面的是水平,一般情况下使用水平的。



10

from django import forms
from django.contrib import admin
from myapp.models import Person

class PersonForm(forms.ModelForm):

    class Meta:
        model = Person
        exclude = ['name']

class PersonAdmin(admin.ModelAdmin):
    exclude = ['age']
    form = PersonForm


自定义form,并且引入到所用的ModelAdmin中,着对于某些密码字段,自定义设置非常有用    自定义form https://docs.djangoproject.com/en/1.6/ref/forms/api/



11.

from django.db import models
from django.contrib import admin

# Import our custom widget and our model from where they're defined
from myapp.widgets import RichTextEditorWidget
from myapp.models import MyModel

class MyModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': RichTextEditorWidget},
    }




设置字段属性,比如文本域的列和行等。


no comments
Share

发表评论