Polymorphic admin interface #10

merged 11 commits into from Aug 6, 2012


None yet
2 participants

vdboor commented Jul 5, 2012

Hi Chris,

While using django-polymorphic for my app, I've build a generic admin interface that displays the polymorphic models in the edit/delete views of the admin. It was extracted out of django-fluent-pages / django-polymorphic-tree where it was originally developped.

You can find the code attached here, and the DOCS.rst is updated with an example how to use it.

I noticed the rest of the project still has older python compatibility. If this is still needed in your opinion, the string formatting will have to be changed back to the % syntax. It's using python 2.6 str.format() syntax currently.


vdboor added some commits Jul 5, 2012

@vdboor vdboor Added polymorphic admin interface
Extracted from django-fluent-pages, ready for other apps too.
The polymorphic admin is implemented via a parent admin for the base
model, and separate admin interfaces for the child models.

The parent model needs to inherit PolymorphicParentModelAdmin,
and override `get_admin_for_model()` and `get_child_model_classes()`
to find the child admin interfaces.

The derived models have their own `ModelAdmin` class, which inherits
from `PolymorphicChildModelAdmin`. The parent admin redirects it's
change and delete views to the child admin.

By adding `polymorphic` to the INSTALLED_APPS, the breadcrumbs will be
fixed as well, to remain unchanged between the child applications.
@vdboor vdboor Adding PolymorphicChildModelAdmin to __all__ as well 2e76811
@vdboor vdboor Improve PolymorphicParentAdmin, simplify, fix templates
During the development of django-polymorphic-tree it was discovered that
the PolymorphicParentModelAdmin could actually be made much simpler.
It features a `child_models` attribute now, so there is very little code
needed to actually implement a polymorphic admin now.

Also found various issues which are together fixed in this commit for
@vdboor vdboor Added requires files to MANIFEST.in and setup.py 0950b86
@vdboor vdboor Added `url` in setup.py, so sdist actually works again. 42d525a
@vdboor vdboor Update the example app to demonstrate the polymorphic admin
This really begs for a separate folder, but I leave that to a new commit
for now.
@vdboor vdboor Fix settings.py for Django 1.4 d5b1b6b

vdboor commented Jul 13, 2012

as far as I'm concerned some of this could be merged into just one commit, but for the sake of sanity in this pull request I haven't changed that :)

vdboor added some commits Jul 13, 2012

@vdboor vdboor Remove abc marker because methods are no longer abstract 8d426d9
@vdboor vdboor Minor extension: allow apps to override the type label in the add for…
…m easily

When overriding apps, this turns out to be a very useful feature to
@vdboor vdboor Change the child model registration to fix raw_id_fields.
As discovered in django-polymorphic-tree and django-fluent-pages,
the raw_id_fields didn't work in Django 1.4 because the fields actively
check which models are actually registered in the admin site.

Hence, the parent admin site _registry is inserted in the child admin as
well. This also completely moves the initialisation of the child admin
into this class, using a `get_child_models()` function,
akin to the static `child_models` attribute.
@vdboor vdboor Also update the DOCS for the get_child_models() admin change. bba8db1

chrisglass commented Aug 6, 2012

Fantastic! Thanks a lot for your contribution!

@chrisglass chrisglass added a commit that referenced this pull request Aug 6, 2012

@chrisglass chrisglass Merge pull request #10 from vdboor/master
Polymorphic admin interface

@chrisglass chrisglass merged commit 28b8885 into django-polymorphic:master Aug 6, 2012

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