I need to make a request on the model himself :
class Course(models.Model):
owner = models.ForeignKey(User, related_name='course', limit_choices_to={'userprofile__status': 'teacher'})
class Assignment (models.Model):
course = models.ForeignKey(Course, related_name='assignment')
admins = models.ManyToManyField(User, blank=True, null=True, limit_choices_to={'userprofile__status': 'teacher'})
I need admin contain all users (with teacher as status) without the owner. I have tried with Q objects but it was not a success…
I’m not sure if you can do this right on the model, but if you could it would be done with
F. Something like:You have to use
Qbecause you can’t assert a negative with the dictionary pattern. The~negates the secondQandF('owner_id')is use to select the value for owner.Like I said, though, I haven’t tried to do this myself, so I can’t say if it will work or not. You’ll just have to give it a whirl and let us know.