Rubick
Rubick

Reputation: 309

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 (models.Model):
    projectLeader = models.ForeignKey('anmeldung.AbstractUser', blank=True, null=True, limit_choices_to={'workingproject': limit},)

class AbstractUser in models.py of application named "anmeldung"

class AbstractUser(AbstractBaseUser, PermissionsMixin):
    workingproject = models.ManyToManyField('szenario.Project', blank=True)

For 'limit' i've used several things like self.id, obj.id but cant figure out whats correct. I'm quite new to Django and all the similar questions i've found didnt help me (could be i just didnt get the answers).

Upvotes: 1

Views: 866

Answers (0)

Related Questions