django-admin-filters

Django admin add custom filter

这一生的挚爱 提交于 2019-12-05 00:18:31
i'm using django 1.10 and I need to display data and create a filter based on a value from a different model(which has a foreign key referencing my model that is used on the admin template) These are my 2 models: This one is used to generate the template: class Job(models.Model): company = models.ForeignKey(Company) title = models.CharField(max_length=100, blank=False) description = models.TextField(blank=False, default='') store = models.CharField(max_length=100, blank=True, default='') phone_number = models.CharField(max_length=60, null=True, blank=True) This is the other one that holds a

Possible to limit filters ManyToMany/Foreign Key in Django admin for a model where the relationship is defined on the other model?

馋奶兔 提交于 2019-12-04 15:39:48
So the title is a bit obtuse, I know, but I couldn't think of a more succinct way to state it. Here's the issue: I've created two proxy models for "user types", both inheriting from django.contrib.auth.User. Each has a custom manager limiting the queryset to items belonging to a particular Group. Specifically, there's a PressUser which is any user belonging to the "Press" group and StaffUser which is any user in any other group than "Press". The issue is that when I add 'groups' to list_filters on my StaffUsers modeladmin, the resulting filter options are every group available, including

Feeding a current filter selection to another custom SimpleListFilter in Django

做~自己de王妃 提交于 2019-12-04 12:05:43
I am trying to make the prompts of one filter change in response to the current selection made in another filter. I am pretty lost as to how to get the currently selected value of the AttributeCategoryFilter passed into the AttributeFilter. I am using Django 1.4-dev. Trying to figure out if I should be using RelatedFieldListFilter for this purpose. It looks like these features are so young as to not have (m)any examples floating around in the wild yet. class AttributeCategoryFilter(SimpleListFilter): title = _('Attribute Category') parameter_name = 'attribute_category' def lookups(self,

Django admin inline model for User

爱⌒轻易说出口 提交于 2019-12-04 10:53:02
问题 I have model as class Employer(models.Model): create_user = models.ForeignKey(User,unique=False,null=True, related_name='%(class)s_user_create') update_user = models.ForeignKey(User,unique=False,null=True, related_name='%(class)s_user_update') and I would like to list all Employer objects while I was at details of user in Django admin panel. I have written something like admin.py class EmployerInline(admin.TabularInline): model = Employer class UserAdmin(admin.ModelAdmin): inlines = [

Minimize the list filter in django-admin

两盒软妹~` 提交于 2019-12-03 09:22:45
问题 I quite like the filter feature of django admin views ( list_filter ). But, on views with a lot of fields, I would really like the ability to minimize/expand it with a click, to save screen real-estate and also because it sometimes actually hides stuff. Is there an easy way to add a collapse button (some already existing plugin I haven't found or something similar)? 回答1: Given that you now have jQuery in django admin, it's easy to bind a slideToggle() to the titles in the List Filter. This

Django: Filtering by %filter% not allowed

三世轮回 提交于 2019-12-01 03:00:41
I inherited a Django v1.2.4 application and am in the process of adding several fixes and improvements. During this process, I suddenly began to encounter the following error: SuspiciousOperation at /hometeam/admin/players/playeryear/ Filtering by team__season__season_start_date__year not allowed This error is displayed in the admin interface popups when I try to select an item for an input field (accessed via the magnifying glass associated with the fields). I have debugging turned on, but I am unable to determine where this error is occurring or which recent change caused it to start. Can

How to fix/set column width in a django modeladmin change list table when a list_filter is added?

≯℡__Kan透↙ 提交于 2019-11-29 04:34:12
I'm working on improving the admin.py in a django project, and while I'm not totally jazzed about how the table was coming out with three fields in the list_diplay, at least it's better than just getting a default object list with one column spanning the whole page... Anyway, what I'm asking is why if this: class FieldAdmin(admin.ModelAdmin): list_display = ('name', 'label', 'standard', ) looks like this: When I add a list_filter, like this: class FieldAdmin(admin.ModelAdmin): list_display = ('name', 'label', 'standard', ) list_filter = ['standard',] Why does it look like this? Is there a way

Filtering Django Admin by Null/Is Not Null

拈花ヽ惹草 提交于 2019-11-29 03:55:35
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ... In this model's ModelAdmin, how would I allow it to be filtered by whether or not referrer is null? By default, adding referrer to list_filter causes a dropdown to be shown that lists every person record, which may be in the hundreds of thousands, effectively preventing the page from loading. Even if it loads, I still can't filter by the criteria I want. i.e. How would I modify this so that the dropdown only lists "All", "Null", or "Not Null" choices? I've seen some posts that

How to fix/set column width in a django modeladmin change list table when a list_filter is added?

廉价感情. 提交于 2019-11-27 18:36:47
问题 I'm working on improving the admin.py in a django project, and while I'm not totally jazzed about how the table was coming out with three fields in the list_diplay, at least it's better than just getting a default object list with one column spanning the whole page... Anyway, what I'm asking is why if this: class FieldAdmin(admin.ModelAdmin): list_display = ('name', 'label', 'standard', ) looks like this: When I add a list_filter, like this: class FieldAdmin(admin.ModelAdmin): list_display =

Filtering Django Admin by Null/Is Not Null

 ̄綄美尐妖づ 提交于 2019-11-27 17:55:31
问题 I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ... In this model's ModelAdmin, how would I allow it to be filtered by whether or not referrer is null? By default, adding referrer to list_filter causes a dropdown to be shown that lists every person record, which may be in the hundreds of thousands, effectively preventing the page from loading. Even if it loads, I still can't filter by the criteria I want. i.e. How would I modify