【问题标题】:How can I filter users in django to many to many fields?如何将 django 中的用户过滤到多对多字段?
【发布时间】:2020-11-19 10:35:54
【问题描述】:

这是我的模型:

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

如何在学生中查看请求用户?

【问题讨论】:

    标签: python sql django


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 2015-07-18
      • 1970-01-01
      • 2020-03-20
      • 2021-07-10
      • 2018-10-19
      • 2023-03-16
      • 2011-07-26
      • 2016-12-13
      相关资源
      最近更新 更多