python - How to count all users in reverse relationship -



python - How to count all users in reverse relationship -

using django orm create method on company returns user count.

this have tried (see company_user_count method):

user model:

class appuser(abstractbaseuser): email = models.emailfield( verbose_name='email address', max_length=254, unique=true, db_index=true, ) company = models.foreignkey('company', related_name="users")

company model:

class company(models.model): name = models.charfield(max_length=60) def company_user_count(self): homecoming company.objects.filter(users__company=self.company).annotate(user_count=count('users'))

above seems homecoming actual object , not simple count (int)

def company_user_count(self): homecoming self.users.count()

python django django-orm

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -