44đź‘Ť
Wrap those fields on their own tuple.
class TestAdmin(admin.ModelAdmin):
fields = (
'field1',
('field2', 'field3'),
'field4'
)
In the above example, fields field2
and field3
are shown on one line.
2đź‘Ť
I’m afraid there’s not an easy way to do it.
One option is to override the change_form.html template for that ModelAdmin and style the form as you like.
Another alternative is to do custom ModelForm and define a field with a widget that renders two input fields, in the form’s .save() method, set the widget resulting value (a tuple) to both fields.
- [Django]-Django [Errno 13] Permission denied: '/var/www/media/animals/user_uploads'
- [Django]-Django: Display current locale in a template
- [Django]-TypeError: ManyRelatedManager object is not iterable
2đź‘Ť
There is an article may be useful
http://amk1.wordpress.com/2010/09/23/a-2-column-django-admin-form/
Article is quote below:
Django is great. The bundled admin interface makes it better. But as the number of items on the form gets bigger, the amount of wasted space increases because the layout is single column. Coupled with left alignment on wide-screen monitors, my users usually end their day with a condition we call “eyeballs misalignment”.
So I improvised and changed the form (and StackedInline) to a 2-up layout. No more “eyeballs misalignment”.
The corresponding template for Django 1.2.1 (/contrib/admin/templates/admin/includes/fieldset.html) looks like this, modified lines highlighted:
<fieldset class="module aligned {{ fieldset.classes }}"> {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %} {% if fieldset.description %} <div class="description">{{ fieldset.description|safe }}</div> {% endif %} <table border=0 width=100%> {% for line in fieldset %} {% cycle '<tr>' '' %} <td width=50%> <div style="border-bottom:0" class="form-row{% if line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}"> {{ line.errors }} {% for field in line %} <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}> {% if field.is_checkbox %} {{ field.field }}{{ field.label_tag }} {% else %} {{ field.label_tag }} {% if field.is_readonly %} <p>{{ field.contents }}</p> {% else %} {{ field.field }} {% endif %} {% endif %} {% if field.field.field.help_text %} <p class="help">{{ field.field.field.help_text|safe }}</p> {% endif %} </div> {% endfor %} </div> </td> {% cycle '' '</tr>' %} {% endfor %} </table> </fieldset>
- [Django]-Django 2 – How to register a user using email confirmation and CBVs?
- [Django]-How to work around lack of support for foreign keys across databases in Django
- [Django]-Django translate variable content in template
2đź‘Ť
this has worked for me
fieldsets=(
("My Group",{"fields": (tuple(['field1','field1']),),}),
)
- [Django]-Bulk create model objects in django
- [Django]-Django content types – how to get model class of content type to create a instance?
- [Django]-Copy file from one model to another
1đź‘Ť
It’s stupid, but yes, if you’re going to use the fieldsets
tuple-within-a-tuple method, you have to then specify all the fields that should show on your form.
- [Django]-Django javascript files
- [Django]-Django Manager Chaining
- [Django]-Appending multiple querystring variables with curl
1đź‘Ť
Agreed, that its annoying, but its tuple of tuples from list of fields.
you can use list comprehension and change list to tuple.
Here is an example for skipping some fields, that you want to give some special attention WHILE including rest normal way.
skipped=[]
alist = [field.name for field in <model_name>._meta.fields if field.name not in skipped]
fieldsets = tuple(alist)
*** play with skipped ***
with small tweaking this should work.
- [Django]-Django url debugger
- [Django]-Generating a Random Hex Color in Python
- [Django]-Failing to install psycopg2-binary on new docker container