我需要查看没有任何组的用户。我试图进行查询, .except
但由于许多字段而失败...
我的模型:
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True)
courses_list = models.ManyToManyField('Course', blank=True)
group_list = models.ManyToManyField('Group', blank=True)
class Group(models.Model):
name = models.CharField(max_length=30)
assignment = models.ForeignKey(Assignment)
members = models.ManyToManyField(UserProfile, through=UserProfile.group_list.through, blank=True)
class Assignment (models.Model):
course = models.ForeignKey(Course)
class Course(models.Model):
subscribed = models.ManyToManyField(UserProfile, through= UserProfile.courses_list.through, blank=True)
所以,我需要选择订阅了assignment.course.subscribed.all
没有任何组的作业(全部发送)的用户(问题是我只需要处理与此作业相关的组)
我试过groupless = detailedassignment.course.subscribed.exclude(username = group_list.filter(assignment=detailedassignment).members.username.all())
了,但它根本不起作用(我认为当我看到代码时这是正常的..)
编辑 :
我以某种方式删除了关系,现在我的模型是:
My models :
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True)
class Group(models.Model):
name = models.CharField(max_length=30)
assignment = models.ForeignKey(Assignment)
members = models.ManyToManyField(UserProfile, blank=True)
class Assignment (models.Model):
course = models.ForeignKey(Course)
class Course(models.Model):
subscribed = models.ManyToManyField(UserProfile, blank=True)
我试过使用:
groupless = detailedassignment.course.subscribed.exclude(user__username__in = Group.objects.filter(assignment=detailedassignment).members.objects.values_list('user__username'))
但是我有'QuerySet' object has no attribute 'members'