mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 19:43:59 +03:00
Fixes #380
This commit is contained in:
parent
df689a7442
commit
2a2ce406bc
|
@ -522,7 +522,10 @@ class HyperlinkedRelatedField(RelatedField):
|
|||
view_name = self.view_name
|
||||
request = self.context.get('request', None)
|
||||
format = self.format or self.context.get('format', None)
|
||||
kwargs = {self.pk_url_kwarg: obj.pk}
|
||||
pk = getattr(obj, 'pk', None)
|
||||
if pk is None:
|
||||
return
|
||||
kwargs = {self.pk_url_kwarg: pk}
|
||||
try:
|
||||
return reverse(view_name, kwargs=kwargs, request=request, format=format)
|
||||
except:
|
||||
|
|
|
@ -224,11 +224,12 @@ class TestOptionalRelationHyperlinkedView(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""
|
||||
Create 1 OptionaRelationModel intances.
|
||||
Create 1 OptionalRelationModel intances.
|
||||
"""
|
||||
OptionalRelationModel().save()
|
||||
self.objects = OptionalRelationModel.objects
|
||||
self.detail_view = OptionalRelationDetail.as_view()
|
||||
self.data = {"url": "http://testserver/optionalrelation/1/", "other": None}
|
||||
|
||||
def test_get_detail_view(self):
|
||||
"""
|
||||
|
@ -238,5 +239,4 @@ class TestOptionalRelationHyperlinkedView(TestCase):
|
|||
request = factory.get('/optionalrelationmodel-detail/1')
|
||||
response = self.detail_view(request, pk=1).render()
|
||||
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
self.assertEquals(response.data, self.data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user