title: How to create a filter on the ForeignKey Field in a Django Model?
body: <p>I have a <code>Detail</code> Model which has a ForeignKey of the default <code>User</code> Model of Django. It works fine, but I want the ForeignKey to be attached to only those users which are neither staff nor superuser.</p>
  
  <p>My <code>Detail</code> model is below:</p>
  
  <pre><code>class Detail(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      subject = models.CharField(max_length=50)
      skype_session_attendance = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(20)], verbose_name="Skype Session Attendances (of this subject, in numbers)", help_text="Enter the numbers of skype sessions of this subject, the student attended out of 20.")
      internal_course_marks = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(40)], verbose_name="Internal Course Marks (of this subject, in numbers)", help_text="Enter the total internal course marks of this subject, the student obtained out of 40.")
      programming_lab_activity = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(25)], verbose_name="Programming Lab Activities (of this subject, in numbers)", help_text="Enter the total numbers of programming lab activities of this subject, the student participated in, out of 25.")
      mid_term_marks = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(45)], verbose_name="Mid_Term Marks (of this subject, in numbers)", help_text="Enter the total mid-term marks of this subject, the student obtained out of 45.")
      final_term_marks = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(90)], verbose_name="Final_Term Marks (of this subject, in numbers)", help_text="Enter the total final-term marks of this subject, the student obtained out of 90.")
  
      def __str__(self):
          return f'{self.user.username}-{self.subject}'
  </code></pre>
  
  <p>I want something like below:</p>
  
  <pre><code>user = models.ForeignKey(User, on_delete=models.CASCADE, filter(not user.is_superuser, not user.is_staff))
  </code></pre>
  
  <p>But it does not work, anyone know how can I accomplish it?</p>