问题描述:

I'm not sure the title is correct for what I'm asking, but I'll try my best with english:

I have 2 models:

class Definition(models.Model):

name = models.CharField(max_length=100, blank=True, null=True)

definition = models.CharField(max_length=1000, blank=True, null=True)

creator = models.ForeignKey(User, related_name='definition_ex', blank=True, null=True)

and

class DefinitionGroup(models.Model):

name = models.CharField(max_length=100, blank=True, null=True)

group = models.ForeignKey(Class, related_name = 'definition_group_by_date')

date = models.DateTimeField(blank=True, null=True)

answers = models.ManyToManyField(Definition, related_name='definition_answers', blank=True, null=True)

Ok, what I what to do is:

dg = list(DefinitionGroup.objects.filter(group=g).filter(date__lte=datetime.date.today()).exclude(answers.creator=user))

But I'm getting an error I don't know how to solve.

Any tips on how I can do that?

网友答案:

One issue is:

.exclude(answers.creator=user))

you cant do that, try this:

.exclude(answers__creator=user))
相关阅读:
Top