django-admin-filters

Admin action- queryset to apply Many to Many

最后都变了- 提交于 2019-12-12 03:25:23
问题 How do I use the admin action to create a queryset which will apply a Many-to-Many value? I understand the 'value' will have to already exist (in my case, the colour itsel will have to exist). Models class Colours(models.Model): colour_name = models.CharField(max_length=50) class Car(models.Model): brand = models.CharField(max_length=200) available_colours = models.ManyToManyField(Colours, blank=True) Admin.py class CarAdmin(admin.ModelAdmin): actions = ['Red'] Attempt 1: only works for FK

limit the choices for objects related to the chosen in the select

无人久伴 提交于 2019-12-11 07:02:28
问题 I wonder if anyone would know a way to return the categories related to the session chosen in the select options. Example: class Session(models.Model): name = models.CharField("Sessão", max_length=100) slug = models.SlugField("Slug", max_length=100) class Category(models.Model): session = models.ForeignKey(Session, verbose_name='Sessão', on_delete=models.CASCADE, max_length=100, default=1, blank=True, null=True) category = models.CharField("Categoria", max_length=100) slug = models.SlugField(

Feeding a current filter selection to another custom SimpleListFilter in Django

丶灬走出姿态 提交于 2019-12-09 19:52:10
问题 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

Django Admin: How do I filter on an integer field for a specific range of values

倖福魔咒の 提交于 2019-12-09 17:10:39
问题 How do I create a filter in Django Admin to only display records where an integer value lies between two values? For example, if I have a model Person, which has an age attribute, and I only want to display Person records where age is between 45 and 65. 回答1: What you are looking is http://djangosnippets.org/snippets/587/ - the snippet is kinda old but works just fine after an additional minor change. I uploaded the patched version at https://gist.github.com/1009903 回答2: You can Filter the

django admin list_filter “or” condition

北战南征 提交于 2019-12-08 19:14:20
问题 sorry if this question has been answered before, but I did a lot of googling without success. I know how to create custom list_filter s in admin views (e.g. subclassing SimpleFilter ). What I really would like, is a way (on the admin list view) to "check" different filters that combines them in a OR formula. As an example, suppose you have: # models.py class Foo(models.Model): foobar = ... foofie = ... ... # admin.py class FooAdmin(admin.ModelAdmin): list_filter = ( "foobar", "foofie" ) ...

django ForeignKey model filter in admin-area?

末鹿安然 提交于 2019-12-08 07:29:19
Hi I need really very very simple example. First my models: #This my student models from django.db import models SEX_CHOICES= ( ('M', 'Male'), ('F', 'Female'), ) class Students(models.Model): student_name = models.CharField(max_length=50) student_sex = models.CharField(max_length=8, choices=SEX_CHOICES) student_city = models.Charfield(max_length=50) student_bio = models.TextField() def __unicode__(self): return self.student_name O.K. Let see my ClassRooms Model. #This my ClassRooms models from django.db import models from myproject.students.models import * class ClassRooms(models.Model): class

Hide certain fields in Django admin site for different user

寵の児 提交于 2019-12-08 02:02:10
问题 I have an admin site that I need to open up to more admins. Currently my model looks like class YouTube(models.Model): name = models.CharField(max_length=100) credit_card_number = models.CharField(max_length=100) Is there a way in the admin site frame work to make it so that only superusers can see the credit card number? In the admin site framework, I can only see the ability to add, edit, delete. 回答1: Create method YouTube.get_cc_root_only , where you are to check if user is root, and use

Django Admin change_list filtering multiple ManyToMany

∥☆過路亽.° 提交于 2019-12-07 14:57:19
问题 In the Django-Admin you have the possibility to define list_filter on fields of the model. This is working for ManyToMany-Fields as well. class ModelA(models.Model): name = models.CharField(max_length=100, verbose_name="Name") class ModelB(models.Model): model_a_relation = models.ManyToManyField(ModelA) class ModelBAdmin(ModelAdmin): list_filter = [model_a_relation, ] admin.site.register(ModelB, ModelBAdmin) Now, I can filter my list of elements of ModelB by relation to ModelA in the Admin

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

不想你离开。 提交于 2019-12-06 09:52:12
问题 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

Hide certain fields in Django admin site for different user

断了今生、忘了曾经 提交于 2019-12-06 07:38:39
I have an admin site that I need to open up to more admins. Currently my model looks like class YouTube(models.Model): name = models.CharField(max_length=100) credit_card_number = models.CharField(max_length=100) Is there a way in the admin site frame work to make it so that only superusers can see the credit card number? In the admin site framework, I can only see the ability to add, edit, delete. Create method YouTube.get_cc_root_only , where you are to check if user is root, and use it in YouTubeAdmin class ( list_display ) UPDATED: class XyzAdmin(admin.ModelAdmin): def get_cc_root_only