Polymorphic admin interface #10

Merged
merged 11 commits into from Aug 6, 2012

Projects

None yet

2 participants

@vdboor
Collaborator
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.

Greetings,
Diederik

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.
5d65bf4
@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
pulling.
b2e308d
@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.
a6d62ed
@vdboor vdboor Fix settings.py for Django 1.4 d5b1b6b
@vdboor
Collaborator
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
have.
0b608cc
@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.
0d5f2fd
@vdboor vdboor Also update the DOCS for the get_child_models() admin change. bba8db1
@chrisglass
Collaborator

Fantastic! Thanks a lot for your contribution!

@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