From 2421f10ab5d167e841cca1aed295abd71cfc0dc0 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Thu, 18 Jul 2013 16:38:14 +0200 Subject: [PATCH 1/3] Simplifies the two remaining templates (for grappelli support). --- .../templates/admin/polymorphic/change_form.html | 14 ++++---------- .../admin/polymorphic/delete_confirmation.html | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/polymorphic/templates/admin/polymorphic/change_form.html b/polymorphic/templates/admin/polymorphic/change_form.html index 56043a1..4224c12 100644 --- a/polymorphic/templates/admin/polymorphic/change_form.html +++ b/polymorphic/templates/admin/polymorphic/change_form.html @@ -1,12 +1,6 @@ {% extends "admin/change_form.html" %} -{% load i18n polymorphic_admin_tags %} +{% load polymorphic_admin_tags %} -{# fix breadcrumb #} -{% block breadcrumbs %}{% if not is_popup %}{% breadcrumb_scope base_opts %} - -{% endbreadcrumb_scope %}{% endif %}{% endblock %} +{% block breadcrumbs %} + {% breadcrumb_scope base_opts %}{{ block.super }}{% endbreadcrumb_scope %} +{% endblock %} diff --git a/polymorphic/templates/admin/polymorphic/delete_confirmation.html b/polymorphic/templates/admin/polymorphic/delete_confirmation.html index c37c385..ca0073d 100644 --- a/polymorphic/templates/admin/polymorphic/delete_confirmation.html +++ b/polymorphic/templates/admin/polymorphic/delete_confirmation.html @@ -1,12 +1,6 @@ {% extends "admin/delete_confirmation.html" %} -{% load i18n polymorphic_admin_tags %} +{% load polymorphic_admin_tags %} -{% block breadcrumbs %}{% breadcrumb_scope base_opts %} - -{% endbreadcrumb_scope %}{% endblock %} +{% block breadcrumbs %} + {% breadcrumb_scope base_opts %}{{ block.super }}{% endbreadcrumb_scope %} +{% endblock %} From 9a068dde78fe8c77387234667f2fd2c86847576a Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Thu, 18 Jul 2013 18:32:41 +0200 Subject: [PATCH 2/3] Doc typos. --- docs/advanced.rst | 4 ++-- docs/index.rst | 4 ++-- docs/managers.rst | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index 2d24159..044d3d4 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -99,7 +99,7 @@ model as the root of a polymorphic inheritance tree:: from thirdparty import ThirdPartyModel - class MyThirdPartyBaseModel(PolymorhpicModel, ThirdPartyModel): + class MyThirdPartyBaseModel(PolymorphicModel, ThirdPartyModel): pass # or add fields Or instead integrating the third party model anywhere into an @@ -181,7 +181,7 @@ Using enhanced Q-objects in any Places -------------------------------------- The queryset enhancements (e.g. ``instance_of``) only work as arguments -to the member functions of a polymorphic queryset. Occationally it may +to the member functions of a polymorphic queryset. Occasionally it may be useful to be able to use Q objects with these enhancements in other places. As Django doesn't understand these enhanced Q objects, you need to transform them manually into normal Q objects before you can feed them diff --git a/docs/index.rst b/docs/index.rst index f1fe11a..e07be4c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -27,7 +27,7 @@ Using vanilla Django, we get the base class objects, which is rarely what we wan Features -------- -* Full admin integation. +* Full admin integration. * ORM integration: * support for ForeignKey, ManyToManyField, OneToOneField descriptors. @@ -37,7 +37,7 @@ Features * Combining querysets of different models (``qs3 = qs1 | qs2``) * Support for custom user-defined managers. -* Uses the minumum amount of queries needed to fetch the inherited models. +* Uses the minimum amount of queries needed to fetch the inherited models. * Disabling polymorphic behavior when needed. diff --git a/docs/managers.rst b/docs/managers.rst index c7c6beb..8ab35b0 100644 --- a/docs/managers.rst +++ b/docs/managers.rst @@ -1,5 +1,3 @@ - - Custom Managers, Querysets & Manager Inheritance ================================================ From ec194164eaa2b95920ed6aaf24ae7e2af2d4cb89 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Thu, 18 Jul 2013 19:31:55 +0200 Subject: [PATCH 3/3] [Docs] Explains how to use django-reversion with polymorphic models. --- docs/admin.rst | 5 ++++ docs/advanced.rst | 3 +++ docs/index.rst | 5 ++-- docs/third-party.rst | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 docs/third-party.rst diff --git a/docs/admin.rst b/docs/admin.rst index 12e8e56..7d46842 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -46,13 +46,18 @@ use the ``base_form`` and ``base_fieldsets`` instead. The ``PolymorphicChildMode automatically detect the additional fields that the child model has, display those in a separate fieldset. +.. _admin-example: + Example ------- +The models are taken from :ref:`advanced-features`. + .. code-block:: python from django.contrib import admin from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin + from .models import ModelA, ModelB, ModelC class ModelAChildAdmin(PolymorphicChildModelAdmin): diff --git a/docs/advanced.rst b/docs/advanced.rst index 044d3d4..3b7a2a3 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -1,8 +1,11 @@ +.. _advanced-features: + Advanced features ================= In the examples below, these models are being used:: + from django.db import models from polymorphic import PolymorphicModel class ModelA(PolymorphicModel): diff --git a/docs/index.rst b/docs/index.rst index e07be4c..ce707f1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,8 +30,8 @@ Features * Full admin integration. * ORM integration: - * support for ForeignKey, ManyToManyField, OneToOneField descriptors. - * support for proxy models + * Support for ForeignKey, ManyToManyField, OneToOneField descriptors. + * Support for proxy models. * Filtering/ordering of inherited models (``ArtProject___artist``). * Filtering model types: ``instance_of(...)`` and ``not_instance_of(...)`` * Combining querysets of different models (``qs3 = qs1 | qs2``) @@ -59,6 +59,7 @@ Advanced topics advanced managers + third-party changelog contributing diff --git a/docs/third-party.rst b/docs/third-party.rst new file mode 100644 index 0000000..03efe3d --- /dev/null +++ b/docs/third-party.rst @@ -0,0 +1,56 @@ +Third-party applications support +================================ + +Django-reversion support +------------------------ + +`Django-reversion `_ works as +expected with polymorphic models. However, they require more setup than +standard models. We have to face these problems: + +* The children models are not registered in the admin site. + You will therefore need to manually register them to django-reversion. +* Polymorphic models use + `multi-table inheritance `_. + The django-reversion wiki explains + `how to deal with this `_. + + +Example +....... + +The admin :ref:`admin-example` becomes: + +.. code-block:: python + + from django.contrib import admin + from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin + import reversion + from reversion import VersionAdmin + from .models import ModelA, ModelB, ModelC + + + class ModelAChildAdmin(PolymorphicChildModelAdmin): + base_model = ModelA + base_form = ... + base_fieldsets = ( + ... + ) + + class ModelBAdmin(VersionAdmin, ModelAChildAdmin): + # define custom features here + + class ModelCAdmin(ModelBAdmin): + # define custom features here + + + class ModelAParentAdmin(VersionAdmin, PolymorphicParentModelAdmin): + base_model = ModelA + child_models = ( + (ModelB, ModelBAdmin), + (ModelC, ModelCAdmin), + ) + + reversion.register(ModelB, follow=['modela_ptr']) + reversion.register(ModelC, follow=['modelb_ptr']) + admin.site.register(ModelA, ModelAParentAdmin)