How to I show a list of ForeignKey reverse lookups in the DJango admin interface?

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

Show a ManyToManyField as Checkboxes in Django Admin

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

different fields for add and change pages in admin

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)

change list display link in django admin

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

Filtering by custom date range in Django admin

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

Make boolean values editable in list_display?

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”

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)