Django

Code

Changeset 7617

Show
Ignore:
Timestamp:
06/11/08 15:28:37 (5 months ago)
Author:
brosner
Message:

newforms-admin: Added inline documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/docs/admin.txt

    r7616 r7617  
    331331.. _the select_related() docs: ../db-api/#select-related 
    332332 
     333``inlines`` 
     334----------- 
     335 
     336See ``InlineModelAdmin`` objects below. 
     337 
    333338``ordering`` 
    334339------------ 
     
    423428    an index. Currently this is only available for MySQL. 
    424429 
     430``InlineModelAdmin`` objects 
     431============================ 
     432 
     433The admin interface has the ability to edit models on the same page as a 
     434parent model. These are called inlines. You can add them a model being 
     435specifing them in a ``ModelAdmin.inlines`` attribute:: 
     436 
     437    class BookInline(admin.TabularInline): 
     438        model = Book 
     439     
     440    class AuthorAdmin(admin.ModelAdmin): 
     441        inlines = [ 
     442            BookInline, 
     443        ] 
     444 
     445Django provides two subclasses of ``InlineModelAdmin`` and they are:: 
     446 
     447    * ``TabularInline`` 
     448    * ``StackedInline`` 
     449 
     450The difference between these two is merely the template used to render them. 
     451 
     452``InlineModelAdmin`` options 
     453----------------------------- 
     454 
     455The ``InlineModelAdmin`` class is a subclass of ``ModelAdmin`` so it inherits 
     456all the same functionality as well as some of its own: 
     457 
     458``model`` 
     459~~~~~~~~~ 
     460 
     461The model in which the inline is using. This is required. 
     462 
     463``fk_name`` 
     464~~~~~~~~~~~ 
     465 
     466The name of the foreign key on the model. In most cases this will be dealt 
     467with automatically, but ``fk_name`` must be specified explicitly if there are 
     468more than one foreign key to the same parent model. 
     469 
     470``formset`` 
     471~~~~~~~~~~~ 
     472 
     473This defaults to ``BaseInlineFormset``. Using your own formset can give you 
     474many possibilities of customization. Inlines are built around 
     475`model formsets`_. 
     476 
     477.. _model formsets: ../modelforms/# 
     478 
     479``form`` 
     480~~~~~~~~ 
     481 
     482The value for ``form`` is inherited from ``ModelAdmin``. This is what is 
     483passed through to ``formset_factory`` when creating the formset for this 
     484inline. 
     485 
     486``extra`` 
     487~~~~~~~~~ 
     488 
     489This controls the number of extra forms the formset will display in addition 
     490to the initial forms. See `extra in formsets`_ for more information. 
     491 
     492``max_num`` 
     493~~~~~~~~~~~ 
     494 
     495This controls the maximum number of forms to show in the inline. This doesn't 
     496directly corrolate to the number of objects, but can if the value is small 
     497enough. See `max_num in model formsets`_ for more information. 
     498 
     499``template`` 
     500~~~~~~~~~~~~ 
     501 
     502The template used to render the inline on the page. 
     503 
     504``verbose_name`` 
     505~~~~~~~~~~~~~~~~ 
     506 
     507An override to the ``verbose_name`` found in the model's inner ``Meta`` class. 
     508 
     509``verbose_name_plural`` 
     510~~~~~~~~~~~~~~~~~~~~~~~ 
     511 
     512An override to the ``verbose_name_plural`` found in the model's inner ``Meta`` 
     513class. 
     514 
     515Working with a model with two or more foreign keys to the same parent model 
     516--------------------------------------------------------------------------- 
     517 
     518It is sometimes possible to have more than one foreign key to the same model. 
     519Take this model for instance:: 
     520 
     521    class Friendship(models.Model): 
     522        to_person = models.ForeignKey(Person, related_name="friends") 
     523        from_person = models.ForeignKey(Person, related_name="from_friends") 
     524     
     525If you wanted to display an inline on the ``Person`` admin add/change pages 
     526you need to explicitly define the foreign key since it is unable to do so 
     527automatically:: 
     528 
     529    class FriendshipInline(admin.TabularInline): 
     530        model = Friendship 
     531        fk_name = "to_person" 
     532     
     533    class PersonAdmin(admin.ModelAdmin): 
     534        inlines = [ 
     535            FriendshipInline, 
     536        ] 
     537 
    425538``AdminSite`` objects 
    426539=====================