Questions tagged [limit-choices-to]
28 questions
19
votes
1 answer
Django limit_choices_to for multiple fields with "or" condition
I am trying to limit choices for a field, by checking values of the two columns, share_holder and distributor. If either of them is true, then I want that choice.
With the below version, I only get choices satisfying both conditions ('share_holder':…

hercules.cosmos
- 265
- 1
- 3
- 10
7
votes
3 answers
Django: "limit_choices_to" doesn't work on ManyToManyField
I am running Django 1.1 and cannot get the "limit_choices_to" option for my ManytoManyField to work.
I have two models:
class MemberPhoto(ImageModel):
title = models.CharField(_('title'), max_length=255, blank=True, null=True)
caption …

Kyle Duncan
- 283
- 4
- 12
6
votes
3 answers
Django MTMField: limit_choices_to = other_ForeignKeyField_on_same_model?
I've got a couple django models that look like this:
from django.contrib.sites.models import Site
class Photo(models.Model):
title = models.CharField(max_length=100)
site = models.ForeignKey(Site)
file =…

saturdayplace
- 8,370
- 8
- 35
- 39
3
votes
3 answers
limit choices to foreignkey using middleware
I'm looking to do something like this:
Model limit_choices_to={'user': user}
with some differences.
Some models may explain:
class Job(models.Model):
name = models.CharField(max_length=200)
operators = models.ManyToManyField(User)
class…

Antonius Common
- 2,931
- 5
- 32
- 32
3
votes
1 answer
Django: How to limit_choices_to when using custom intermediate table
Let me start by saying that I am working with a legacy database so avoiding the custom intermediate table is not an option.
I'm looking for an alternative way to get the limit_choices_to functionality as I need to only present the options flagged by…

JPLaverdure
- 43
- 7
3
votes
0 answers
Adding another select field to django admin interface
So in one app i have four models. From first to last they are name 'brand', 'mark', 'type', 'engine'.
Mark has a foreign key to brand, type has a foreign key to mark, and engine has one to type.
In the admin interface when I add a mark I get a…

Robert Foxa
- 91
- 1
- 6
2
votes
1 answer
Dynamic filtering on FK in Django Admin
I have one Product Model that has a FK to price, as one product can contain many prices. But I also want to be able to pick which one of those many prices should be the actual price, therefore I have both price (in Product Model) and product (in…

orwellian
- 388
- 4
- 15
1
vote
1 answer
is it possible to have two parameters in limit_choices_to in django models?
I'll shorten the code as simple as possible. Supposedly, we do have two models.
models.py > Products table
CATEGORY = (
('Hard Disk Drive', 'Hard Disk Drive'),
('Solid State Drive', 'Solid State Drive'),
('Graphics Card', 'Graphics…

dev_ren
- 31
- 7
1
vote
1 answer
In Django forms.ModelChoiceField HOWTO restrict displayed choices but set one of the restricted values during cleanup
I have a custom field which subclasses ModelMultipleChoiceField. I provide the choices to be displayed via queryset parameter. This queryset excludes certain values. My problem comes when during cleanup operation for some workflows I need to select…

Chantz
- 5,883
- 10
- 56
- 79
1
vote
1 answer
How to display CHOICES in Django ModelForm
I have a policy_category model with 16 categories.
I have a Response model to record survey answers. The model includes a field to record the respondent's 1-5 rating for each of the policy categories. (policy_1_rank..policy_16_rank, etc.)
I can't…

jm2288
- 53
- 8
1
vote
0 answers
Django: limit_choices_to to current objects id
Im using Django 1.11.6 and trying to limit the choices of projectLeader in my Project class to a list of AbstracUser which have the Projects id in their ManytoMany field workingproject.
class Project in models.py of one app
class Project…

Rubick
- 139
- 3
- 11
1
vote
2 answers
filtering ForeignKey by object ID
I have a CarType that has a ForeignKey BodyMaterial in my models.py:
class BodyMaterial(models.Model):
location = models.ForeignKey('CarType')
name = models.CharField(max_length=255)
class…

user1549769
- 25
- 4
1
vote
3 answers
How to define django foreign key limit_choices_to constraint which has reference to it's own model?
Here are the models. I need to avoid the reference of Filter objects in the FilterValue model which are being already referenced in the FilterValue model.
class Filter(models.Model):
name = models.CharField('Name', max_length=255)
…

Babu
- 2,548
- 3
- 30
- 47
0
votes
2 answers
Django model list from ManyToManyField other model
I'm looking into creating some kind of dashboard to do some easy server admin tasks online. As much as possible stored in the database, so I could configure there tasks online instead of programming them.
What I'm trying to achieve in my data model…

Ron
- 119
- 1
- 10
0
votes
0 answers
Display the value of current foreignkey in update form when limiting queryset choice
I have a model named TimeTable (as shown below). In my update form I want to display the current value of the foreignkey field (say 'mon_1'). Since I am limiting the foreignkey choices using queryset in my form, the current value isn't being…

Rahul
- 17
- 6