如何在Django视图中过滤ManyToManyfield

时间:2019-11-03 16:10:25

标签: django django-views

如何过滤与相应类别中的用户相关的问题?

views.py

questoes = Questao.objects.filter(idCategoria__in=[request.user.usuario.idCategoria])

models.py

class Categoria(models.Model):
    idCategoria = models.CharField(primary_key=True)

class Usuario(models.Model):
    idCategoria = models.ManyToManyField(Categoria)

0 个答案:

没有答案