title: Tastypie annoate / groupby returns a "pk" error
body: <p>When using django's annotate to get a "group by" it makes sense it returns objects without PK. As it wouldn't make sense to group by a field, sum up some other fields, and get single row PK IDs.</p>
  
  <p>I assume I'm doing this wrong in tastypie. But I couldn't see a way of doing group bys from the documentation.</p>
  
  <p>So I've added a queryparam "groupby" to my custom resource class. In the "apply_filters" I let tastypie do its usual thing, then I step in and apply a django "group by":</p>
  
  <pre><code>return q.values('type').annotate(*(Sum(x) for x in fields_to_aggregate)).order_by()
  </code></pre>
  
  <p>This returns a Queryset of objects, that only have "type" field, and the correctly summed up fields.</p>
  
  <p>The error I get from tastypie is:</p>
  
  <pre><code>    Traceback (most recent call last):  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 228, in wrapper  
      response = callback(request, *args, **kwargs)  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 468, in dispatch_list  
      return self.dispatch('list', request, **kwargs)  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 500, in dispatch  
      response = method(request, **kwargs)  
    File "/srv/attrib-backend/backend/api/utils.py", line 69, in get_list  
      for obj in to_be_serialized[self._meta.collection_name]  
    File "/srv/attrib-backend/backend/api/utils.py", line 69, in &lt;listcomp&gt;  
      for obj in to_be_serialized[self._meta.collection_name]  
    File "/srv/attrib-backend/backend/api/utils.py", line 114, in full_dehydrate  
      data[field_name] = method(bundle)  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 1093, in dehydrate_resource_uri  
      return self.get_resource_uri(bundle)  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 837, in get_resource_uri  
      return self._build_reverse_url(url_name, kwargs=self.resource_uri_kwargs(bundle_or_obj))  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 816, in resource_uri_kwargs  
      kwargs.update(self.detail_uri_kwargs(bundle_or_obj))  
    File "/usr/local/lib/python3.6/dist-packages/tastypie/resources.py", line 793, in detail_uri_kwargs  
      kwargs[self._meta.detail_uri_name] = getattr(bundle_or_obj, self._meta.detail_uri_name)  
  AttributeError: 'dict' object has no attribute 'pk'  
  </code></pre>
  
  <p>I've tried adding "pk" to the values() func, but I still get this error. Plus it doesn't make sense to me to return the Id of rows in aggregation.<br>
  I can see it's trying to add a "resource_uri" to the objects, is there a way to turn this off/disable resource_uri generating?<br>
  As I said, it doesnt make sense to have an ID concept when aggregating.  </p>
  
  <p>I believe my issue stems from having to use queryset.values() to get django's group by aggregation. But the objects return, all the fields tastypie doesn't "see" as attributes. See in following error:</p>
  
  <pre><code>"The object 
  {
      type': 'My Type X', 
      'field_one__sum': 4,
      'field_two__sum': Decimal('1045.76'),
  }
  has an empty attribute 'type' and doesn't allow a default or null value."
  </code></pre>
  
  <p>Thanks for any help or pointers!</p>