Admin

Django admin integration for stories management.

Admin Classes

PostAdmin

class PostAdmin(model, admin_site)

Bases: FrontendEditableAdminMixin, ModelAppHookConfig, GrouperModelAdmin

app_config_initial_fields = ('app_config', 'content__language')
extra_grouping_fields: tuple[str, ...] = ('language',)

Indicates additional grouping fields such as "language" for example. Additional grouping fields create tabs in the change form and a dropdown menu in the change list view.

Note

All fields serving as extra grouping fields must be part of the admin’s fieldsets setting for GrouperModelAdmin to work properly. In the change form the fields will be invisible.

inlines = []
list_display = ('title', 'author', 'app_config')
search_fields = ('content__title', 'content__subtitle', 'author__last_name', 'author__first_name')
readonly_fields = ('date_created', 'date_modified')
date_hierarchy = 'date_published'
autocomplete_fields = ['author', 'related']
frontend_editable_fields = ('title', 'abstract', 'post_text')
enhance_exclude = ('main_image', 'tags')
actions = ['enable_comments', 'disable_comments']
class Media

Bases: object

js = ('djangocms_stories/js/Sortable.min.js', 'djangocms_stories/js/related-sortable.js')
title(obj)
get_form(request, obj=None, **kwargs)

Adds the language from the request to the form class

can_change_content(request, content_obj)

Returns True if user can change content_obj

enable_comments(request, queryset)

Bulk action to enable comments for selected posts. queryset must not be empty (ensured by django CMS).

disable_comments(request, queryset)

Bulk action to disable comments for selected posts. queryset must not be empty (ensured by django CMS).

get_list_filter(request)

Return a sequence containing the fields to be displayed as filters in the right sidebar of the changelist page.

lookup_allowed(lookup, *args)
get_urls()

Customize the modeladmin urls

has_restricted_sites(request)

Whether the current user has permission on one site only

Parameters:

request – current request

Returns:

boolean: user has permission on only one site

get_restricted_sites(request)

The sites on which the user has permission on.

To return the permissions, the method check for the get_sites method on the user instance (e.g.: return request.user.get_sites()) which must return the queryset of enabled sites. If the attribute does not exists, the user is considered enabled for all the websites.

Parameters:

request – current request

Returns:

boolean or a queryset of available sites

get_fieldsets(request, obj=None)

Customize the fieldsets according to the app settings

Parameters:
  • request – request

  • obj – post

Returns:

fieldsets configuration

save_model(request, obj, form, change)

Save/create both grouper and content object

get_queryset(request)

Annotates content fields with the name “content__{field_name}” to the grouper queryset if for all content fields that appear in the

get_content_obj(obj)

Given the HttpRequest, the parent ModelForm instance, the list of inline formsets and a boolean value based on whether the parent is being added or changed, save the related objects to the database. Note that at this point save_form() and save_model() have already been called.

formfield_for_manytomany(db_field, request, **kwargs)

Get a form Field for a ManyToManyField.

get_search_results(request, queryset, search_term)

Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.

property media

PostContentAdmin

class PostContentAdmin(model, admin_site)

Bases: FrontendEditableAdminMixin, ModelAdmin

frontend_editable_fields = ['post_text', 'title', 'subtitle']
change_view(request, object_id, form_url='', extra_context=None)

Redirect to grouper change view to allow for FrontendEditing of Post Content fields

get_model_perms(request)

Return empty perms dict thus hiding the model from admin index.

property media

CategoryAdmin

class CategoryAdmin(model, admin_site)

Bases: FrontendEditableAdminMixin, TranslatableAdmin

form

alias of CategoryAdminForm

list_display = ['name', 'parent', 'app_config', 'all_languages_column']
fieldsets = ((None, {'fields': ('parent', 'app_config', 'name', 'slug', 'meta_description')}), ('Info', {'classes': ('collapse',), 'fields': ('abstract',)}), ('Image', {'classes': ('collapse',), 'fields': ('main_image', ('main_image_thumbnail', 'main_image_full'))}))
autocomplete_fields = ['parent']
search_fields = ['translationas__name', 'meta_description']
class Media

Bases: object

css = {'all': ('djangocms_stories/css/djangocms_stories_admin.css',)}
property media

ConfigAdmin

class ConfigAdmin(model, admin_site)

Bases: TranslatableAdmin

list_display = ('namespace', 'app_title', 'object_name')
form

alias of StoriesConfigForm

property declared_fieldsets
get_fieldsets(request, obj=None)

Fieldsets configuration

get_readonly_fields(request, obj=None)

Make namespace field readonly if object exists

property media
save_model(request, obj, form, change)

Clear menu cache when changing menu structure

Admin Mixins

ModelAppHookConfig

class ModelAppHookConfig

Bases: object

app_config_selection_title = 'Select app config'
app_config_selection_desc = 'Select the app config for the new object'
app_config_initial_fields = ('app_config',)
app_config_values = {}
get_fieldsets(request, obj=None)

If the apphook config must be selected first, returns a fieldset with just the app config field and help text :param request: :param obj: :return:

get_config_data(request, obj, name)

Method that retrieves a configuration option for a specific AppHookConfig instance

Parameters:
  • request – the request object

  • obj – the model instance

  • name – name of the config option as defined in the config form

Return value:

config value or None if no app config is found

render_app_config_form(request, form)

Render the app config form

changeform_view(request, object_id=None, form_url='', extra_context=None)

Override the changeform_view to set the app_config field to the correct value

For the add view it checks whether the app_config is set; if not, a special form to select the namespace is shown, which is reloaded after namespace selection. If only one namespace exists, the current is selected and the normal form is used.

Admin Filters

SiteListFilter

class SiteListFilter(request, params, model, model_admin)

Bases: SimpleListFilter

title = 'site'
parameter_name = 'sites'
lookups(request, model_admin)

Must be overridden to return a list of tuples (value, verbose value)

queryset(request, queryset)

Return the filtered queryset.

Extension Registration

register_extension(klass)
unregister_extension(klass)