2019-06-14 18:20:29 +02:00
|
|
|
from django import forms
|
2015-12-26 18:46:51 +01:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2015-12-26 19:51:22 +01:00
|
|
|
from .models import Article, ArticleProxy, Site
|
|
|
|
|
|
|
|
|
2019-06-14 18:20:29 +02: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-26 19:51:22 +01:00
|
|
|
class ArticleInline(admin.TabularInline):
|
|
|
|
model = Article
|
|
|
|
fields = ["title"]
|
2019-06-14 18:20:29 +02:00
|
|
|
form = ArticleAdminForm
|
2015-12-26 19:51:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SiteAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [ArticleInline]
|
|
|
|
|
2015-12-26 18:46:51 +01:00
|
|
|
|
|
|
|
site = admin.AdminSite(name="admin")
|
|
|
|
site.register(Article)
|
|
|
|
site.register(ArticleProxy)
|
2015-12-26 19:51:22 +01:00
|
|
|
site.register(Site, SiteAdmin)
|
2023-02-08 18:37:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CustomAdminSite(admin.AdminSite):
|
|
|
|
def get_log_entries(self, request):
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
|
|
|
log_entries = super().get_log_entries(request)
|
|
|
|
return log_entries.filter(
|
|
|
|
content_type__in=ContentType.objects.get_for_models(
|
|
|
|
*self._registry.keys()
|
|
|
|
).values()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
custom_site = CustomAdminSite(name="custom_admin")
|
|
|
|
custom_site.register(Article)
|