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 2d24159..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): @@ -99,7 +102,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 +184,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..ce707f1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -27,17 +27,17 @@ 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. - * 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``) * 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. @@ -59,6 +59,7 @@ Advanced topics advanced managers + third-party changelog contributing 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 ================================================ 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) 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 %}