django-admin

Is there an elegant way to have a list_filter for a M2M field in the Django admin?

If I have a Pizza model and a Topping model, with m2m between them, is there some quick elegant way to add to the admin list page for either of them a list filter for all pizzas which contain a certain topping / all toppings that are contained in a certain pizza? The built-in list_filter doesn't support m2m fields so I'm looking for som...

How can I call model methods or properties from Django Admin?

Is there a natural way to display model methods or properties in the Django admin site? In my case I have base statistics for a character that are part of the model, but other things such as status effects which affect the total calculation for that statistic: class Character(models.Model): base_dexterity = models.IntegerField(defa...

Modify on-the-fly verbose_name in a model field on django admin

Hi I have this sample model working with the admin class Author(models.Model): name = models.CharField(_('Text in here'), max_length=100) with verbose_name set as ugettext_lazy 'Text in here', but sometimes, depending on the site_id i want to present a diferent verbose name, so I modified the init in this way def __init__(self, ...

Django admin causes high load for one model...

In my Django admin, when I try to view/edit objects from one particular model class the memory usage and CPU rockets up and I have to restart the server. I can view the list of objects fine, but the problem comes when I click on one of the objects. Other models are fine. Working with the object in code (i.e. creating and displaying) is o...

How can I limit ModelAdmin queryset to user-editable items when using object permissions?

I'm trying to implement Florian's object permissions system from his article on Django Advent, but I'm running into an issue trying to limit the queryset returned to only items the user has permission to edit/view. Florian mentions it in his section on wrapping the admin, but skips over it. I can't see a good way to filter the queryset. ...

Making only a part of model field available in Django

Hello I have a such model: GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female') ) class Profile(models.Model): user = models.ForeignKey(User) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) class FrontPage(models.Model): female = models.ForeignKey(User,related_name="female") male = models.ForeignKey(User,re...

verbose_name for a model's method

How can I set a verbose_name for a model's method, so that it might be displayed in the admin's change_view form? example: class Article(models.Model): title = models.CharField(max_length=64) created_date = models.DateTimeField(....) def created_weekday(self): return self.created_date.strftime("%A") in admin.py: ...

How to customize a many-to-many inline model in django admin

I'm using the admin interface to view invoices and products. To make things easy, I've set the products as inline to invoices, so I will see the related products in the invoice's form. As you can see I'm using a many-to-many relationship. In models.py: class Product(models.Model): name = models.TextField() price = models.Deci...

Formatting inline many-to-many related models presented in django admin

I've got two django models (simplified): class Product(models.Model): name = models.TextField() price = models.IntegerField() class Invoice(models.Model): company = models.TextField() customer = models.TextField() products = models.ManyToManyField(Product) I would like to see the relevant products as a nice tabl...

django admin site - filtering available objects for user

I have models that belong to some 'group' (Company class). I want to add users, who will also belong to a one group and should be able to edit/manage/add objects with membership in associated group. something like: class Company() class Something() company = ForeignKey(Company) user Microsoft_admin company = ForeignKey(Company) ...

Django, Redirecting staff from login to the admin site.

So my site basically has 2 kinds of ways to login, one of them is for the common users, who get the regular screen that asks them for username and password, the other way its for staff. The staff login should redirect them to the admin site after logging in, but for some reason the redirect doesnt happen, it stays on the same login page...

django admin filter tweaking

Hi, I want to use django's admin filter on the list page. The models I have are something like this: class Location(model): name = CharField() class Inquiry(Model): name = CharFiled() location = ManyToManyField(Location) Now I want to filter Inquiries, to display only those that contain relation to specific Location object. ...

Using ckEditor on selective text areas in django admin forms

Hi, I want to apply ckeditor on specific textarea in django admin form not on all the text areas. Like snippet below will apply ckeditor on every textarea present on django form: class ProjectAdmin(admin.ModelAdmin): formfield_overrides = {models.TextField: {'widget': forms.Textarea(attrs={'class':'ckeditor'})}, } class...

IntegrityError with Booleand Fields and Postgresql

I have this simple Blog model: class Blog(models.Model): title = models.CharField(_('title'), max_length=60, blank=True, null=True) body = models.TextField(_('body')) user = models.ForeignKey(User) is_public = models.BooleanField(_('is public'), default = True) When I insert a blog in admin interface, I get this err...

Fixing Django Admin collapse error.

Hi. I've been following the Django tutorial, and so far everything's been working as planned. Except "collapse"ing. On my admin page, I get the error in my Javascript Console: Uncaught TypeError: Object #<an Object> has no method 'first' collapse.min.js:1 I'm assuming this is a bug in jQuery, or the collapse script, however my qu...

Django 1.2: Dates in admin forms don't work with Locales (I10N=True)

I have an application in Django 1.2. Language is selectable (I18N and Locale = True) When I select the english lang. in the site, the admin works OK. But when I change to any other language this is what happens with date inputs (spanish example): Correctly, the input accepts the spanish format %d/%m/%Y (Even selecting from the calendar...

display one-to-many relationship for a model in Django admin (list mode)

In Django admin site, when listing all the objects for a given model, I know we can customize which columns get displayed for a ModelA via list_display Say that ModelA has a one-to-many relationship with ModelB. I would like to add another column on the listing page for ModelA, where each entry is a URL pointing to all objects of ModelB...

Django admin- constrain visibility of models and model instances based on who logged in

Using the django admin, I would like to be able to specify which models a user sees when he logs in. For a stretch goal, for each model types a user can see, I would like to specify a filter to limit which instances of the model the user can see. Could someone please provide a pointer for how to go about achieving this? ...

Django internationalization for admin pages - translate model name and attributes

Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way to translate the model name and the attributes for admin pages? I did not find anything about this in the documentation: http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ http://www.djangobook.com/en/2.0/chapter...

displaying list of registered user in django-admin

My Book model has an author attribute which today is simply a CharField. The value for author should be one of the registered users of my Django site. When creating a new Book object in Django admin, I would like author to be displayed as a combo box showing all registered users. How would I go about achieving this? ...