Django Admin: How do I set the ordering of inline elements?
This works now so you can just do something like: class MyModelInline(admin.TabularInline): model = MyModel ordering = (“field_name”,)
This works now so you can just do something like: class MyModelInline(admin.TabularInline): model = MyModel ordering = (“field_name”,)
By default, a ModelAdmin will only let you manage the model “itself”, not related models. In order to edit the related Unit model, you need to define an “InlineModelAdmin” – such as admin.TabularInline – and attach it to your CustomerAdmin. https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects For example, in your admin.py: from django.contrib import admin from models import Customer, Unit … Read more
The solution by Masatsugu Hosoi works fine, but you can also use the decorator and set short_description on the property getter (fget): @property def my_property(self): return u’Returns some calculations’ my_property.fget.short_description = u’Property X’
From this answer it seems like it is possible to use ModelAdmin.formfield_overrides to override the ManyToManyField to use CheckBoxSelectMultiple: from django.db import models from django.contrib import admin from django.forms import CheckboxSelectMultiple class MyModelAdmin(admin.ModelAdmin): formfield_overrides = { models.ManyToManyField: {‘widget’: CheckboxSelectMultiple}, } I haven’t tried it and am merely quoting from the source, but it seems plausible. … Read more
This is an old question but I wanted to add that the add_view and change_view methods can be modified for this purpose: class SoftwareVersionAdmin(ModelAdmin): … def add_view(self,request,extra_content=None): self.exclude = (‘product’,’version_number’,) return super(SoftwareVersionAdmin,self).add_view(request) def change_view(self,request,object_id,extra_content=None): self.exclude = (‘product’,’description’,) return super(SoftwareVersionAdmin,self).change_view(request,object_id)
I believe the correct way of doing it, is subclassing ChangeList and override the url_for_result method to create the correct change url you want. Override the get_changelist in the admin.ModelAdmin subclass to return the new class: from django.contrib.admin.views.main import ChangeList from django.contrib.admin.util import quote class FooChangeList(ChangeList): def url_for_result(self, result): pk = getattr(result, self.pk_attname) return ‘/foos/foo/%d/’ … Read more
With the class-based views in newer Django versions, one can use this in urls.py: from django.views.generic import TemplateView url(r’^about’, TemplateView.as_view(template_name=”path/to/about_us.html”), name=”about”),
In django 1.4, you can user list_filter. try: from django.contrib.admin import DateFieldListFilter class PersonAdmin(ModelAdmin): list_filter = ( (‘date_field_name’, DateFieldListFilter), ) This will give some built-in ranges, but it will work if you put the date range in url, like: ?date__gte=2009-5-1&date__lt=2009-8-1 If you need a date picker (like jquery), then you need to extend DateFieldListFilter. I … Read more
ModelAdmin.list_editable is what you need, see its doc here. Below you also have an example: class TaskAdmin(models.ModelAdmin): list_display = (…, ‘is_finished’) list_editable = (‘is_finished’,) # this MUST only contain fields that also are in “list_display” #list_display_links = (‘foo’, ‘bar’) # this MUST NOT contain a field in common with “list_editable”