Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Allow specifying instances in admin #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dvarrazzo
Copy link
Contributor

Hello,

this is a work in progress I'm using in a website of mine that allows specifying specific instances to be included in the django admin together with models.

As a specific use case, in my admin I'm displaying the normal Folder model from https://github.com/divio/django-filer, and a specific folder containing certain documents that must be accessible from first level. Such configuration is obtained by:

ADMIN_REORDER = [
    # ...
    dict(app='totus', label='Documents',
        models=(
            dict(model='filer.Folder', label="All files and folders"),
            dict(instance='filer.Folder',
                lookup={"name": "Regulation documents"},
                urlpattern='admin:filer-directory_listing'),
        )),
    # ...
]

urlpattern is optional: the default is the change page of the model specified. If the model is not found no entry is added (consistently with models not found)

The feature can easily lead to requests like "can I add all my objects instances where the owner is the owner of the list, the public property is true etc... So I've changed the configuration: ADMIN_REORDER can now take a function name instead of a list of entries: the function is called with the request as input to get a list of entries. This allows performing queries before visualizing the admin page in order to look for objects matching certain properties.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-0.2%) to 0.775% when pulling de7ac7d on dvarrazzo:instances-in-admin into 6e3ea39 on mishbahr:master.

This is now possible as instances may be returned by a function instead
of being just declared in the settings.
@dvarrazzo
Copy link
Contributor Author

With the last change an instance can be... an instance instead of a class name, which is useful if the config is returned by a function performing a lookup. The lookup dictionary in this case is not required.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-0.2%) to 0.758% when pulling 5dcccda on dvarrazzo:instances-in-admin into 6e3ea39 on mishbahr:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants