tomchristie/django-rest-framework — pull request #694 by craigds (2013-03-01 03:33:04+00:00)
Title: fix function names and dotted lookups for use in PrimaryKeyRelatedField

I've been using this, working fine:

class ExportSerializer(serializers.ModelSerializer):
#...
layers = serializers.RelatedField(many=True, source='get_layers', queryset=ExportLayer.objects.all())

This works fine, but then I tried to use `serializers.PrimaryKeyRelatedField` instead and everything broke:

Traceback:
File "/home/cdestigter/checkout/django/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/home/cdestigter/checkout/django/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/cdestigter/checkout/django/django/views/decorators/csrf.py" in wrapped_view
77. return view_func(*args, **kwargs)
File "/home/cdestigter/checkout/django-rest-framework/rest_framework/views.py" in dispatch
404. response = self.handle_exception(exc)
File "/home/cdestigter/checkout/django-rest-framework/rest_framework/views.py" in dispatch
401. response = handler(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/poppy/exports/views.py" in get
19. return Response(serializer.data)
File "/home/cdestigter/checkout/django-rest-framework/rest_framework/serializers.py" in data
387. self._data = [self.to_native(item) for item in obj]
File "/home/cdestigter/checkout/django-rest-framework/rest_framework/serializers.py" in to_native
279. value = field.field_to_native(obj, field_name)
File "/home/cdestigter/checkout/django-rest-framework/rest_framework/relations.py" in field_to_native
226. return [self.to_native(item.pk) for item in queryset.all()]

Exception Type: AttributeError at /api/v2/exports/
Exception Value: 'function' object has no attribute 'all'

This PR fixes the error.