Is there an up-to-date option for allowing collapsible inlines in the Django admin site?
I've looked at https://code.djangoproject.com/ticket/494, How to add 'collapse' to a Django StackedInline and Grappelli, but none of them seem to work for Django 1.6.1.
Any suggestions?
clps = ('collapse', 'grp-closed')
or
css_classes=('collapse closed',)
These two ways seems to work for me with grappelli, You did not give code info to tell which is relevant,
POST your grappelli dashboard code(or anything else)
Adding this to your inline model (django-grappelli==2.6.5+) :
fieldsets = (
('yoour_description', {
'classes': ('grp-collapse', 'grp-closed'),
'fields' : ('field1', 'field2', ...),
}),
)
Related
I have a User model that has these two fields:
permissions = models.ManyToManyField(Permission)
groups = models.ManyToManyField(Group)
I register the model in the admin. When I view the user model that I made in the admin section I get a multiple select menu that looks like this.
I would much prefer the much better-looking menu like the one that is in the auth user model that comes built into Django admin (looks like this)
Any ideas on what I need to do to be able to access this sort of select menu?
Thanks for your help.
Django newb from PHP (finally)
Use filter_horizontal (or filter_vertical) field in your admin class.
For example:
#admin.register(User)
class UserAdmin(admin.ModelAdmin):
...
filter_horizontal = 'groups', 'permissions', 'any_other_m2m_field'
...
Also link to Django docs:
https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.filter_horizontal
So i work in a company and we constantly need to add view fields for the user, I would like to know if there is a way to make this option available to the end user, for example a dropdown with the options that the model admin where he is allowing.
Today we use the django way of doing admin, for example:
list_display = (
'course',
'class',
'discipline',
'teacher',
'start_date',
'end_date'
)
I don't know if this what you are looking for, but give a try: How can I dynamically specify the "list_display" attribute of a django ModelAdmin class?
A kind regard
Emilio
I'm trying to install the autocomplete-light function in my admin menu. I have added the following in my admin.py. I have install the app in my settings.
class InstitutionAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Institution, exclude = [])
list_display = ('name', 'url',)
autocomplete_fields = ('name')
admin.site.register(Institution, InstitutionAdmin)
added this to autocomplete_light_registry.py:
autocomplete_light.register(InstitutionAdmin)
I don't think I need to at the autocomplete to url right? because this should show up when I go to the admin page in django? What am I missing?
Do autocomplete_light.register() for every model you want to be autocompleted in InstitutionAdmin.form.
http://django-autocomplete-light.readthedocs.org/en/master/api.html#autocomplete_light.registry.AutocompleteRegistry.register
All,
I have a django 1.6 admin page and I would like to use MPTT but whenever I use mptt.admin.MPTTModelAdmin, preserve_filters no longer works. If I use the standard django ModelAdmin, then preserve_filters works great. Any ideas why the MPTTModelAdmin breaks preserve_filters?
For Example:
class GroupAdmin(admin.ModelAdmin):
preserve_filters = True
# Works GREAT and saves the filter when editing/saving a "Group" object
This does not work.
class GroupAdmin(admin.MPTTModelAdmin):
preserve_filters = True
Does not preserve any list_filter choices after saving/editing a "Group" object.
Thanks for any and all help.
I have a model with lots of say CharField fields, that I would like to edit in the admin.
The problem is that each field takes up one line. How should I make them display like this (horizontally):
(source: djangoproject.com)
(they are not foreign keys)
Django 1.2 has ListEdit extension for the Admin
This is how you use it:
class AccountAdmin(admin.ModelAdmin):
list_display = ( 'Name','Type')
list_editable = ( 'Type', )
And this is how it looks like:
(source: v-lad.org)