Django

Code

Ticket #494 (new)

Opened 3 years ago

Last modified 1 week ago

Collapse in admin interface for inline related objects

Reported by: jcstover@nilling.nl Assigned to: xian
Milestone: post-1.0 Component: django.contrib.admin
Version: newforms-admin Keywords: edit_inline, nfa-someday
Cc: eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org, msaelices@yaco.es, upadhyay@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 1
Needs tests: 0 Patch needs improvement: 1

Description

It would be nice if there is a property to tell the admin interface to collapse the related object.

eg: organisatie = meta.ForeignKey?(Organisatie, edit_inline=meta.STACKED, edit_inline_style='collapse')

I changed line 610 in the django/views/admin/main.py to t.append('<fieldset class="module%s">\n' % ((rel_field.rel.edit_inline != meta.TABULAR) and ' aligned collapse' or ' collapse')) and it works. But using a property would be better.

Thanks

Attachments

494.patch (4.2 kB) - added by Antonis Christofides <anthony@itia.ntua.gr> on 11/22/07 09:36:22.
Patch with alternative approach
494.2.patch (4.2 kB) - added by Antonis Christofides <anthony@itia.ntua.gr> on 11/22/07 11:05:35.
Updated patch, fixing a documentation problem
494.3.patch (4.7 kB) - added by aptiko on 09/18/08 08:50:09.
Quick and dirty solution for brainstorming

Change History

09/12/05 14:29:05 changed by jctover@nilling.nl

Since I changed already a few things in the admin view for translation and I'm not experienced with svn yet here are my changes I made to create an inline_style property to make it collapse

in django/core/meta/fields.py line nr 585

  • raw_id_admin=kwargs.pop('raw_id_admin', False)) + raw_id_admin=kwargs.pop('raw_id_admin', False), inline_style=kwargs.pop('inline_style', None))

in django/core/meta/fields.py line nr 654

  • related_name=None, limit_choices_to=None, lookup_overrides=None, raw_id_admin=False): + related_name=None, limit_choices_to=None, lookup_overrides=None, raw_id_admin=False, inline_style=None):

in django/views/admin/main.py line 610

  • t.append('<fieldset class="module%s %s">\n' % ((rel_field.rel.edit_inline != meta.TABULAR) and ' aligned' or )) + t.append('<fieldset class="module%s %s">\n' % ((rel_field.rel.edit_inline != meta.TABULAR) and ' aligned' or , rel_field.rel.inline_style or ))

For using it just include inline_style='collapse' and the related objects are collapsed. Hope you include a better solution to this problem

Johan

09/25/05 17:31:39 changed by jacob

  • owner changed from adrian to jacob.
  • status changed from new to assigned.
  • milestone set to Version 1.0.

10/04/05 17:48:48 changed by jforcier@strozllc.com

  • cc set to jforcier@strozllc.com.

05/03/06 07:55:28 changed by mdt@emdete.de

even the collapse in the related object has no effect. is that a bug?

05/03/06 08:50:28 changed by anonymous

  • cc deleted.

Removed myself from the Cc list (no longer that interested =))

06/12/06 06:45:00 changed by URL

  • type deleted.

09/05/06 10:11:20 changed by eric@aa.usno.navy.mil

  • cc set to eric@aa.usno.navy.mil.
  • type set to defect.

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

01/23/07 08:48:15 changed by Marc Fargas <telenieko@telenieko.com>

Wy don't you use the method provied by http://www.djangoproject.com/documentation/model_api/#id3? It provides almost this, I think.

If it's enought for the reporter, please close the ticket as "worksforme" ;)

01/23/07 13:04:49 changed by jcstover@nilling.nl

I didn't use django for a while, but from what I remember. For a tablular view of related objects you can collapse that view, but not when it is stacked. That was it about. If it is working for stacked objects now its okay.

01/23/07 17:06:26 changed by SmileyChris

  • summary changed from Collapse in admin interface for related objects to Collapse in admin interface for related objects using meta.STACKED.

Can someone confirm this?

01/23/07 17:49:22 changed by Marc Fargas <telenieko@telenieko.com>

  • summary changed from Collapse in admin interface for related objects using meta.STACKED to Collapse in admin interface for related objects using models.STACKED.
  • stage changed from Unreviewed to Design decision needed.

Confirmed, it has to do with the way django/trunk/django/contrib/admin/templates/admin/change_form.html works, it can handle the "classes" attribute for fields (line 36), but not for "edit_inline" relations (stacked or inline) on line 57. And I could not find any easy way to get it working. Maybe django/trunk/django/contrib/admin/templates/admin/edit_inline_stacked.html should get the classes for the related objects but dunno how to pass it.

As a side note, it's models.STACKED not meta.STACKED right now, changing the summary to reflect this.

02/17/07 23:45:52 changed by Gary Wilson <gary.wilson@gmail.com>

  • keywords set to edit_inline.

09/04/07 18:05:21 changed by anonymous

  • summary changed from Collapse in admin interface for related objects using models.STACKED to Collapse in admin interface for inline related objects.

09/14/07 10:55:01 changed by jacob

  • version set to newforms-admin.

-> newforms-admin

09/14/07 14:04:45 changed by jkocherhans

  • owner changed from nobody to xian.
  • status changed from assigned to new.

11/22/07 09:36:22 changed by Antonis Christofides <anthony@itia.ntua.gr>

  • attachment 494.patch added.

Patch with alternative approach

11/22/07 09:38:35 changed by Antonis Christofides <anthony@itia.ntua.gr>

I just uploaded a patch. You append a string with classes to edit_inline, and it uses these classes. For example:

edit_inline = models.TABULAR + 'collapse extrapretty'

11/22/07 11:05:35 changed by Antonis Christofides <anthony@itia.ntua.gr>

  • attachment 494.2.patch added.

Updated patch, fixing a documentation problem

12/01/07 07:12:46 changed by yserrano

  • has_patch set to 1.

12/01/07 07:48:04 changed by yserrano

  • has_patch deleted.

The patch fails on the newforms-admin branch. The file structure has changed from django/contrib/admin/templates/admin/edit_inline_stacked.html to django/contrib/admin/templates/admin/edit_inline/stacked.html

12/07/07 17:07:55 changed by brosner

  • keywords changed from edit_inline to edit_inline, nfa-someday.

Tagging with nfa-someday as this is functionality that is not critical to the merge of the newforms-admin branch.

12/07/07 17:12:28 changed by brosner

  • needs_better_patch set to 1.

04/09/08 06:19:09 changed by Antonis Christofides <anthony@itia.ntua.gr>

Could you please point me to a description of how the newforms-admin branch is managed and what is the policy for patching admin/newforms-admin? Do I need to write two patches, one for old admin and one for new admin?

The second question is whether a better patch in the same spirit would be accepted.

06/16/08 12:33:07 changed by mrts

  • milestone set to post-1.0.

Non-essential for 1.0.

Antonis, you could write a similar patch against trunk when newforms-admin gets merged (and that is really soon now). It will be eventually merged, but probably not before 1.0.

08/13/08 08:44:25 changed by Bernd

  • cc changed from eric@aa.usno.navy.mil to eric@aa.usno.navy.mil, schlaber@gmail.com.

09/18/08 08:36:06 changed by aptiko

  • cc changed from eric@aa.usno.navy.mil, schlaber@gmail.com to eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr.

09/18/08 08:50:09 changed by aptiko

  • attachment 494.3.patch added.

Quick and dirty solution for brainstorming

09/18/08 09:02:37 changed by aptiko

I just uploaded another patch (not including documentation), as proof of concept. It works, but I've done it by doing quite some voodoo debugging. The idea is to add a 'classes' InlineModelAdmin option, with a list of classes. For example:

class BookInline(admin.TabularInline):
    model = Book
    classes = ['collapse', 'extrapretty']

If we like this interface, then please review my patch and help me find out what I didn't get right. However, I think that ideally I'd like another interface: the "fieldsets" ModelAdmin option should be reworked in order to somehow include inline objects. This would also give the flexibility to change the order, allowing them to intermingle with other fieldsets, and so on. But this also means that some conceptual changes should be made, because inline objects are not fieldsets, they are formsets. The "fieldsets" option might need to be renamed to "formsections" or so and its structure enhanced or modified.

09/24/08 04:12:09 changed by aptiko

Note: Apparently the patch I submitted only works if the model contains another fieldset that specifies "classes".

11/17/08 07:25:46 changed by Guilherme M. Gondim <semente@taurinus.org>

  • cc changed from eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr to eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org.

11/19/08 18:18:46 changed by msaelices

  • cc changed from eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org to eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org, msaelices@yaco.es.

11/23/08 00:07:10 changed by amitu

  • cc changed from eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org, msaelices@yaco.es to eric@aa.usno.navy.mil, schlaber@gmail.com, anthony@itia.ntua.gr, semente@taurinus.org, msaelices@yaco.es, upadhyay@gmail.com.

11/23/08 12:02:32 changed by SmileyChris

  • needs_docs set to 1.
  • has_patch set to 1.
  • stage changed from Design decision needed to Accepted.

aptiko's patch looks good. It adds useful functionality and I like the addition of a fieldset to the StackedInline template - I always thought it should have it for consistency.

The patch does incorrectly close <fieldset> with </div>. It also needs to change generic_inlineformset_factory in django.contrib.contenttypes.generic.


Add/Change #494 (Collapse in admin interface for inline related objects)




Change Properties
Action