How to move inline into or above fieldsets in django admin?

6,798 views
Skip to first unread message

mongoose

unread,
Dec 11, 2010, 9:05:11 AM12/11/10
to Django users
Hi there,

Currently I've got a recipe application like this:

class RecipeAdmin(admin.ModelAdmin):
fieldsets = (
('Recipe Details',{
'fields': (
('title', 'slug'),'description', 'difficulty', 'vegetarian',
'serves', ('prep_time', 'cooking_time'), 'categories','tags'
)
}),
('Cooking Instructions', {'fields': ['instructions']}),
)
inlines = [IngredientInline, PhotoInline]

The problem here is that the Ingredients are being listed after the
Cooking Instruction which doesn't really fit. The best would be to
have something like this:

class RecipeAdmin(admin.ModelAdmin):
fieldsets = (
('Recipe Details',{
'fields': (
('title', 'slug'),'description', 'difficulty', 'vegetarian',
'serves', ('prep_time', 'cooking_time'), 'categories','tags'
)
}),

inlines = [IngredientInline, PhotoInline]

('Cooking Instructions', {'fields': ['instructions']}),
)

Thanks a lot!

wayne

unread,
Dec 11, 2010, 12:20:43 PM12/11/10
to Django users
I'm not sure if there is an admin setting that will allow you to
specify this ordering. Either way, you can always override the admin
template for this particular class.

Read about it here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

Wayne

mongoose

unread,
Dec 11, 2010, 2:30:49 PM12/11/10
to Django users
Hi wayne,

to be honest I've no idea how i'd do that by overriding a template.
> Read about it here:  http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-ad...
>
> Wayne

Wayne Smith

unread,
Dec 11, 2010, 4:26:46 PM12/11/10
to django...@googlegroups.com

Well, the template is what controls the ordering of fields.  You can create your own template that Django will then use in the admin interface.  From there you can control exactly how things are displayed.

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

mongoose

unread,
Dec 12, 2010, 2:30:05 AM12/12/10
to Django users
mind giving a short example?
From what I see in the template

{% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" %}
{% endfor %}

{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% endfor %}

I can either have it appear before or after the fieldsets. Not in
between.





On Dec 11, 11:26 pm, Wayne Smith <wayne.tuxro...@gmail.com> wrote:
> Well, the template is what controls the ordering of fields.  You can create
> your own template that Django will then use in the admin interface.  From
> there you can control exactly how things are displayed.
> django-users...@googlegroups.com<django-users%2Bunsu...@googlegroups.com>
> .> For more options, visit this group at
>
> http://groups.google.com/group/django-users?hl=en.
>
>

wayne

unread,
Dec 14, 2010, 2:59:28 PM12/14/10
to Django users


On Dec 12, 1:30 am, mongoose <darrenma1...@gmail.com> wrote:
> mind giving a short example?
> From what I see in the template
>
> {% for fieldset in adminform %}
>   {% include "admin/includes/fieldset.html" %}
> {% endfor %}
>
> {% for inline_admin_formset in inline_admin_formsets %}
>     {% include inline_admin_formset.opts.template %}
> {% endfor %}
>
> I can either have it appear before or after the fieldsets. Not in
> between.

Sorry I haven't gotten back to you. I simply haven't had much time
lately; work and finals.

I am still not entirely sure what you want, but you can move that code
around in your overridden template to get what you want.

For example, if I understand you correctly, something like:

{% for fieldset in adminform %}
  {% include "admin/includes/fieldset.html" %}
{% if fieldset_I_want_for_inlines %}
{% include fieldset inline %}
{% endif %}
{% endfor %}

{% for inline_admin_formset in inline_admin_formsets %}
    {% include inline_admin_formset.opts.template %}
{% endfor %}

HTH,

Wayne
Reply all
Reply to author
Forward
0 new messages