Raise nicer exception if queryset not Set on writable related field. Refs: #338

This commit is contained in:
Tom Christie 2012-10-30 11:10:23 +00:00
parent 0047a46020
commit cea907f172

View File

@ -291,6 +291,9 @@ class PrimaryKeyRelatedField(RelatedField):
return pk
def from_native(self, data):
if self.queryset is None:
raise Exception('Writable related fields must include a `queryset` argument')
try:
return self.queryset.get(pk=data)
except ObjectDoesNotExist:
@ -374,6 +377,8 @@ class HyperlinkedRelatedField(RelatedField):
def from_native(self, value):
# Convert URL -> model instance pk
# TODO: Use values_list
if self.queryset is None:
raise Exception('Writable related fields must include a `queryset` argument')
if value.startswith('http:') or value.startswith('https:'):
# If needed convert absolute URLs to relative path