Re: Prefetch object (django 1.7)

2014-01-30 Thread Marcin Szamotulski
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

Re: Prefetch object (django 1.7)

2014-01-29 Thread Anssi Kääriäinen
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',

Re: Prefetch object (django 1.7)

2014-01-29 Thread Marcin Szamotulski
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 =

Prefetch object (django 1.7)

2014-01-26 Thread Marcin Szamotulski
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