Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13115 closed (worksforme)

Display multiple widgets within a particular admin fieldset horizontally

Reported by: delfick755@… Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords:
Cc: gabrielhurley Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hello,

I wonder if it would be possible to be able to specify to display some controls in an admin add page to be next to each other instead of on top of each other.

I'm not sure I've explained that very well, so I'll add too screenshots. First one is what i have currently for a particular project of mine. The other is a gimped version of what I want.

Thankyou

Attachments (2)

current.png (57.9 KB) - added by anonymous 4 years ago.
desired.png (23.7 KB) - added by anonymous 4 years ago.

Download all attachments as: .zip

Change History (9)

Changed 4 years ago by anonymous

Changed 4 years ago by anonymous

comment:1 Changed 4 years ago by gabrielhurley

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Just FYI, this is not the easiest thing to do. It's not that hard to make a single widget that has multiple fields on one row, but making multiple widgets coexist on one row requires changing how the admin templates render the rows.

Right now it just uses a for loop to render each field in its own div, and render the appropriate label and widget inside that div.

Making it allow horizontally-arranged bits would involve changes to the admin templates, admin stylesheet, and to the forms component itself (to add some sort of attribute determining which fields should be floated next to each other).

You could implement it entirely in admin, but if you're going to do all that work, why not implement it for all forms instead of just admin forms...

comment:2 Changed 4 years ago by ramiro

  • Resolution set to worksforme
  • Status changed from new to closed

You already can do that. Please read carefully the documentation of the fieldsets ModelAdmin option documentation: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets

Post any further question to the django.users mailing list or the #django IRC channel.

comment:3 Changed 4 years ago by gabrielhurley

  • Cc gabrielhurley added
  • Summary changed from Display controls in particular fieldset in django admin add page horizontally to Display multiple widgets within a particular admin fieldset horizontally

I think Ramiro may have slightly misunderstood what the OP was asking for... I'll bring it up on django-developers since I think this is still a worthwhile feature.

comment:4 Changed 4 years ago by foxulet

I have just reached the same issue as described here. And as in the graphic example above, I use grappelli too.
Each field is in it's own div, and if we use field sets then all divs are grouped as we choose inside a single div.

As it would be very difficult to change the code I have just opted to rearrange the fields inside that fieldset using CSS positioning.
But a general layout system would be interesting.

comment:5 Changed 4 years ago by foxulet

And once again the old RTFM applies, and with such a good documentation there's no reason why not to read the Django manual.

To display multiple fields on the same line, wrap those fields in their own tuple. In this example, the first_name and last_name fields will display on the same line:

{
'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
}

comment:6 Changed 4 years ago by gabrielhurley

Thanks foxulet. I can't believe how many times I've read those docs without seeing that tidbit tucked in there! My bad!

comment:7 Changed 4 years ago by delfick

@foxulet : oh, I do read the documentation, it is fantastic documentation. I have the same problem as gabrielhurley, the number of times I have read the documentation and missed that.

However, Thankyou so much for pointing that out, it is perfect.

Sorry I missed it.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.