简体   繁体   中英

How can I filter users in django to many to many fields?

HERE IS MY MODEL:

class Course(models.Model):
    title = models.CharField(max_length=100)
    students = models.ManyToManyField(User,related_name="students")
    crated_at = models.DateField(auto_created=True)

How can I check request user in students?

您可以使用它进行过滤:-

user_filter = Course.objects.filter(user=request.user)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM