# models.py
class Book(TimeStampedModel):
name = models.CharField(_('nome'), max_length=50)
authors = models.ManyToManyField('Author', verbose_name='autores')
price = models.DecimalField(_(u'preço'), max_digits=5, decimal_places=2)
# views.py
class BookList(ListView):
template_name = 'core/book_list.html'
model = Book
def get_queryset(self):
''' use prefetch_related for m2m performance '''
b = Book.objects.prefetch_related('authors').all()
return b
Do you think you really need prefetch_related
to improve queryset's performance? Or do not you? Does Django's CBV automatically do this?