Indeed, I am PostAuthor is a through model. Thanks I understand now how it
works. Prefetch('postauthors', PostAuthors.objects) fails with
AttributeError: Cannot find 'postauthors' on Post object, 'postauthors' is
an invalid parameter to prefetch_related()
So it seems that 'postauthors' is not
To me it seems you are mixing the authors m2m relation and the through
model. The 'authors' relates to User, not PostAuthor. But your queryset is
pointing to PostAuthors.
If you want to fetch PostAuthor instances, then you should likely prefetch
with Prefetch('postauthors',
On 01:42 Mon 27 Jan , Marcin Szamotulski wrote:
> Hello,
>
> I have a model
>
> class Post(models.Model):
>
> ...
> authors = models.ManyToManyField('accounts.User', through='PostAuthor',
> related_name='authors_posts')
>
>
> class PostAuthor(models.Model):
>
> user =
Hello,
I have a model
class Post(models.Model):
...
authors = models.ManyToManyField('accounts.User', through='PostAuthor',
related_name='authors_posts')
class PostAuthor(models.Model):
user = models.ForeignKey('accounts.User')
post = models.ForeignKey(Post)
...
How
4 matches
Mail list logo