mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Raise nicer exception if queryset not Set on writable related field. Refs: #338
This commit is contained in:
parent
0047a46020
commit
cea907f172
|
@ -291,6 +291,9 @@ class PrimaryKeyRelatedField(RelatedField):
|
||||||
return pk
|
return pk
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
|
if self.queryset is None:
|
||||||
|
raise Exception('Writable related fields must include a `queryset` argument')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.queryset.get(pk=data)
|
return self.queryset.get(pk=data)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
|
@ -374,6 +377,8 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
def from_native(self, value):
|
def from_native(self, value):
|
||||||
# Convert URL -> model instance pk
|
# Convert URL -> model instance pk
|
||||||
# TODO: Use values_list
|
# 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 value.startswith('http:') or value.startswith('https:'):
|
||||||
# If needed convert absolute URLs to relative path
|
# If needed convert absolute URLs to relative path
|
||||||
|
|
Loading…
Reference in New Issue
Block a user