# Buggy code
def label_per_data(self, project):
    label_count = Counter()
    user_count = Counter()
    annotation_class = project.get_annotation_class()
    docs = project.documents.all()
    annotations = annotation_class.objects.filter(document_id__in=docs.all())
    for d in annotations.values("label__text", "user__username").annotate(
        Count("label"), Count("user")
    ):
        label_count[d["label__text"]] += d["label__count"]
        user_count[d["user__username"]] += d["user__count"]
    return label_count, user_count


# Traceback (django.core.exceptions.FieldError)
Internal Server Error: /v1/projects/4/statistics
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/doccano/app/api/views.py", line 70, in get
label_count, user_count = self.label_per_data(p)
File "/doccano/app/api/views.py", line 94, in label_per_data
for d in annotations.values('label__text', 'user__username').annotate(Count('label'), Count('user')):
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 750, in values
clone = self._values(*fields, **expressions)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 745, in _values
clone.query.set_values(fields)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1987, in set_values
self.add_fields(field_names, True)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1735, in add_fields
join_info = self.setup_joins(name.split(LOOKUP_SEP), opts, alias, allow_many=allow_m2m)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1473, in setup_joins
names[:pivot], opts, allow_many, fail_on_missing=True,
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1389, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'label' into field. Choices are: created_at, document, document_id, id, manual, prob, text, updated_at, user, user_id

# Fixed code
def label_per_data(self, project):
    annotation_class = project.get_annotation_class()
    return annotation_class.objects.get_label_per_data(project=project)