summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-08-10 04:03:01 +0000
committerBrian Rosner <brosner@gmail.com>2008-08-10 04:03:01 +0000
commit02cc59187be963b6c1ede084a7c9912ea6a1a338 (patch)
treee63c01bb70ef75e1b9b18a51cde787b91a93f907 /docs
parentf6670e1341c6b01c5b24b9274aac05d026e536c5 (diff)
downloaddjango-02cc59187be963b6c1ede084a7c9912ea6a1a338.tar.gz
Fixed #4667 -- Added support for inline generic relations in the admin. Thanks to Honza Král and Alex Gaynor for their work on this ticket.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8279 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/admin.txt41
-rw-r--r--docs/contenttypes.txt34
2 files changed, 70 insertions, 5 deletions
diff --git a/docs/admin.txt b/docs/admin.txt
index d9b3523c04..dcff894c51 100644
--- a/docs/admin.txt
+++ b/docs/admin.txt
@@ -785,6 +785,47 @@ Finally, register your ``Person`` and ``Group`` models with the admin site::
Now your admin site is set up to edit ``Membership`` objects inline from
either the ``Person`` or the ``Group`` detail pages.
+Using generic relations as an inline
+------------------------------------
+
+It is possible to use an inline with generically related objects. Let's say
+you have the following models::
+
+ class Image(models.Model):
+ image = models.ImageField(upload_to="images")
+ content_type = models.ForeignKey(ContentType)
+ object_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey("content_type", "object_id")
+
+ class Product(models.Model):
+ name = models.CharField(max_length=100)
+
+If you want to allow editing and creating ``Image`` instance on the ``Product``
+add/change views you can simply use ``GenericInlineModelAdmin`` provided by
+``django.contrib.contenttypes.generic``. In your ``admin.py`` for this
+example app::
+
+ from django.contrib import admin
+ from django.contrib.contenttypes import generic
+
+ from myproject.myapp.models import Image, Product
+
+ class ImageInline(generic.GenericTabularInline):
+ model = Image
+
+ class ProductAdmin(admin.ModelAdmin):
+ inlines = [
+ ImageInline,
+ ]
+
+ admin.site.register(Product, ProductAdmin)
+
+``django.contrib.contenttypes.generic`` provides both a ``GenericTabularInline``
+and ``GenericStackedInline`` and behave just like any other inline. See the
+`contenttypes documentation`_ for more specific information.
+
+.. _contenttypes documentation: ../contenttypes/
+
``AdminSite`` objects
=====================
diff --git a/docs/contenttypes.txt b/docs/contenttypes.txt
index a4fc045714..4d5fcc6cb8 100644
--- a/docs/contenttypes.txt
+++ b/docs/contenttypes.txt
@@ -72,11 +72,11 @@ together, uniquely describe an installed model:
`the verbose_name attribute`_ of the model.
Let's look at an example to see how this works. If you already have
-the contenttypes application installed, and then add `the sites
-application`_ to your ``INSTALLED_APPS`` setting and run ``manage.py
-syncdb`` to install it, the model ``django.contrib.sites.models.Site``
-will be installed into your database. Along with it a new instance
-of ``ContentType`` will be created with the following values:
+the contenttypes application installed, and then add `the sites application`_
+to your ``INSTALLED_APPS`` setting and run ``manage.py syncdb`` to install it,
+the model ``django.contrib.sites.models.Site`` will be installed into your
+database. Along with it a new instance of ``ContentType`` will be created with
+the following values:
* ``app_label`` will be set to ``'sites'`` (the last part of the Python
path "django.contrib.sites").
@@ -261,3 +261,27 @@ Note that if you delete an object that has a ``GenericRelation``, any objects
which have a ``GenericForeignKey`` pointing at it will be deleted as well. In
the example above, this means that if a ``Bookmark`` object were deleted, any
``TaggedItem`` objects pointing at it would be deleted at the same time.
+
+Generic relations in forms and admin
+------------------------------------
+
+``django.contrib.contenttypes.genric`` provides both a ``GenericInlineFormSet``
+and ``GenericInlineModelAdmin``. This enables the use of generic relations in
+forms and the admin. See the `model formset`_ and `admin`_ documentation for
+more information.
+
+``GenericInlineModelAdmin`` options
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ``GenericInlineModelAdmin`` class inherits all properties from an
+``InlineModelAdmin`` class. However, it adds a couple of its own for working
+with the generic relation:
+
+ * ``ct_field`` - The name of the ``ContentType`` foreign key field on the
+ model. Defaults to ``content_type``.
+
+ * ``ct_fk_field`` - The name of the integer field that represents the ID
+ of the related object. Defaults to ``object_id``.
+
+.. _model formset: ../modelforms/
+.. _admin: ../admin/