Skip to content

Instantly share code, notes, and snippets.

@alexphelps
Created June 23, 2017 17:26
Show Gist options
  • Save alexphelps/fbef6debc5125f73ed9cf629918f0b78 to your computer and use it in GitHub Desktop.
Save alexphelps/fbef6debc5125f73ed9cf629918f0b78 to your computer and use it in GitHub Desktop.
Accounts Table Example
accounts = Account.objects.annotate(client_count=Count('client'), users_count=Count('users'))
account_data = []
for account in accounts:
account_data.append(
{
'id': account.id,
'name': account.name,
'clients': account.client_count,
'users': account.users_count
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment