Questions tagged [limit-choices-to]

28 questions
0
votes
0 answers

Limit Foreignkey Choices based on already obtained values

I have three models which are interlinked hierarchically (see #models.py). In my CreateTimeTable view, I create a timetable for a week and each period of a day takes a 'foreignkey' of a teacher who is inturn linked to his/her subject. Of course no…
Rahul
  • 17
  • 6
0
votes
1 answer

Django Foreign Key limit_choice_to with model object filter

I'm trying to limit the choices for a foreign key in my django admin tool. I stumbled across the limit_choices_to option for the ForeignKey model:…
0
votes
0 answers

How to limit the choice related to FK in DRF backend/admin panel

class Quiz(models.Model): name = models.CharField(max_length=200,default="",blank=False) questions_count = models.IntegerField(default="") description = models.TextField(max_length=10000,default="",blank=False) created =…
0
votes
0 answers

Django: ManyToManyField.limit_choices_to seems not working properly

I have following models: models.py: def limit_name_choices(): return {"pk__gt": Name.objects.last().pk} class Name(models.Model): name = models.CharField(max_length=100) primary = models.BooleanField() class Robject(models.Model): …
0
votes
1 answer

django - admin model assign value to limit_choices_to from another field inside the model

I have extended the admin model, so for each staff member i can assign other customers only if they are in the same group. class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) is_manager =…
Rafi
  • 135
  • 1
  • 9
0
votes
1 answer

limit ForeignKey choices based on another ForeginKey field

Let's say I have an app's structure that looks like this : ** models.py ** Class School(models.Model): name = models.CharField(max_length=500) Class Manager(models.Model) name = models.Charfield(max_length=500) school =…
DjangoGuy
  • 103
  • 2
  • 13
0
votes
3 answers

Django: limit models.ForeignKey results

I have an order model: class Order(models.Model): profile = models.ForeignKey(Profile, null=True, blank=True) Which returns all possible profiles for an order, which is not necessary and slowing down the loading of the admin order page. I want…
James
  • 103
  • 2
  • 9
0
votes
1 answer

Django ForeignKey limit_choices_to multiple child elements

I have the following models: class Person(models.Model): # fields class Teacher(Person): # fields class Student(Person): # fields teacher = models.ForeignKey(teacher) class Staff(Person): # fields class…
0
votes
2 answers

limit_choices_to within Django model

I have a project model. This project contains persons (those who are working on the project). I am trying to also make a model for each project person, including any notes they have on the project and % complete on project. My issue is that I want…
Chad Crowe
  • 1,260
  • 1
  • 16
  • 21
0
votes
1 answer

Django 1.8: access current user (extended) in ForeignKey.limit_choices_to

UPDATE I tried to use CuserMiddleware and used it like this to get the current user: def limit_by_username(): c_username = "" c_user = CuserMiddleware.get_user() if c_user is not None: c_username = c_user[0].username …
jaysonpryde
  • 2,733
  • 11
  • 44
  • 61
0
votes
1 answer

ManyToManyField limit choices to dynamic foreign model

class TrialRun(models.Model): product = models.ForeignKey(NewProduct, verbose_name='Product',) class Component(models.Model): product = models.ForeignKey(NewProduct, verbose_name='Product',) class TrialIssue(models.Model): trialrun =…
user687673
  • 21
  • 1
  • 5
0
votes
0 answers

Limit another app's GenericForeignKey choices

I am writing a reusable Carousel app. It needs to refer to a model in the main project, so I have used a generic foreign key. I have something like this in the reusable app: from django.db import models from django.contrib.contenttypes.models import…
0
votes
1 answer

How to limit choices for a Many to Many relation?

I'm using Python + Django and have this in my model right now: class Team(models.Model): player = models.ManyToManyField(Player, related_name="player", through="Team_Player") squad = models.ManyToManyField(Player, related_name="squad",…
1
2