Skip to content

Instantly share code, notes, and snippets.

@vitorfs
Created October 11, 2016 17:46
Show Gist options
  • Save vitorfs/afae1190a54a6cb4ea27d06bb476bd40 to your computer and use it in GitHub Desktop.
Save vitorfs/afae1190a54a6cb4ea27d06bb476bd40 to your computer and use it in GitHub Desktop.
Removing "sites" from Django's Flatpages
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.utils.translation import ugettext_lazy as _
class CustomFlatPageAdmin(FlatPageAdmin):
fieldsets = (
(None, {'fields': ('url', 'title', 'content',)}),
(_('Advanced options'), {
'classes': ('collapse',),
'fields': ('registration_required', 'template_name'),
}),
)
list_filter = ('registration_required',)
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, CustomFlatPageAdmin)
# If you want, you may also remove the Site from django admin
from django.contrib.sites.models import Site
admin.site.unregister(Site)
@luzdealba
Copy link

hello Vitor, where do you actually locate this file?

@vitorfs
Copy link
Author

vitorfs commented Dec 8, 2019

@luzdealba usually I have a generic Django app named "core" for this kind of use case. So in that case I add this core in the admin.py file inside the core app

@luzdealba
Copy link

@vitorfs oh, that's clever! Will take that idea, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment