2019-06-15 00:20:29 +08:00
|
|
|
from django import forms
|
2015-12-27 01:46:51 +08:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2015-12-27 02:51:22 +08:00
|
|
|
from .models import Article, ArticleProxy, Site
|
|
|
|
|
|
|
|
|
2019-06-15 00:20:29 +08:00
|
|
|
class ArticleAdminForm(forms.ModelForm):
|
|
|
|
nolabel_form_field = forms.BooleanField(required=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Article
|
|
|
|
fields = ['title']
|
|
|
|
|
|
|
|
@property
|
|
|
|
def changed_data(self):
|
|
|
|
data = super().changed_data
|
|
|
|
if data:
|
|
|
|
# Add arbitrary name to changed_data to test
|
|
|
|
# change message construction.
|
|
|
|
return data + ['not_a_form_field']
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2015-12-27 02:51:22 +08:00
|
|
|
class ArticleInline(admin.TabularInline):
|
|
|
|
model = Article
|
|
|
|
fields = ['title']
|
2019-06-15 00:20:29 +08:00
|
|
|
form = ArticleAdminForm
|
2015-12-27 02:51:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SiteAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [ArticleInline]
|
|
|
|
|
2015-12-27 01:46:51 +08:00
|
|
|
|
|
|
|
site = admin.AdminSite(name='admin')
|
|
|
|
site.register(Article)
|
|
|
|
site.register(ArticleProxy)
|
2015-12-27 02:51:22 +08:00
|
|
|
site.register(Site, SiteAdmin)
|