﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34354	models. Manager annotate() queryset conflict with models.Model	David Pratten	nobody	"With

{{{
class MyPapersManager(models.Manager):
     def get_queryset(self): 
         return super().get_queryset().annotate(count_of_keywords=Coalesce(Count('keywordspapers'),0))   # .filter(in_scope=True) works fine here
}}}

{{{
class MyPapers(models.Model):
    objects = MyPapersManager() 
    count_of_keywords = models.IntegerField() # generated by manager above!
    keywordspapers = models.ManyToManyField(to='Keywords', blank=True)
}}}

and 
{{{
class MyPapersAdmin(admin.ModelAdmin):
    list_display = (""count_of_keywords"",)
}}}


Results in runtime error {{{The annotation 'count_of_keywords' conflicts with a field on the model.}}}

However, f I remove the {{{count_of_keywords}}} field from the models.Model I get a start up error: {{{<class 'literature.admin.MyPapersAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'count_of_keywords', which is not a callable, an attribute of 'MyPapersAdmin', or an attribute or method on 'literature.MyPapers'.}}}

What is the correct way to add a computed field to a model in Admin land?

Thanks

David
"	New feature	closed	contrib.admin	4.1	Normal	duplicate	Possible		Unreviewed	0	0	0	0	0	0
