0

I've got a model named MyUser with a user_type field which can be of the following different user types

USER_TYPE_STUDENT

USER_TYPE_TEACHER

USER_TYPE_DIRECTOR

In one of the models, I've got the following field

student = models.ForeignKey(MyUser, null=True, related_name='requests',
                            limit_choices_to={'user_type': MyUser.USER_TYPE_STUDENT}, ...)

As you can read, it uses

limit_choices_to={'user_type': MyUser.USER_TYPE_STUDENT}

Thing is, in a OneToOneField field (students_or_teachers), I would like to declare that field is limited to user_type USER_TYPE_STUDENT or USER_TYPE_TEACHER.

How can that be done?

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145

1 Answers1

1

Use a __in lookup:

limit_choices_to = {
    "user_type__in": (MyUser.USER_TYPE_STUDENT, MyUser.USER_TYPE_TEACHER)
    }
bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118