Given an object, return the URL that hyperlinks to the object. May raise a `NoReverseMatch` if the `view_name` and `lookup_field` attributes are not configured to correctly match the URL conf.
(self, obj, view_name, request, format)
| 319 | raise exc.with_traceback(sys.exc_info()[2]) |
| 320 | |
| 321 | def get_url(self, obj, view_name, request, format): |
| 322 | """ |
| 323 | Given an object, return the URL that hyperlinks to the object. |
| 324 | |
| 325 | May raise a `NoReverseMatch` if the `view_name` and `lookup_field` |
| 326 | attributes are not configured to correctly match the URL conf. |
| 327 | """ |
| 328 | # Unsaved objects will not yet have a valid URL. |
| 329 | if hasattr(obj, 'pk') and obj.pk in (None, ''): |
| 330 | return None |
| 331 | |
| 332 | lookup_value = getattr(obj, self.lookup_field) |
| 333 | kwargs = {self.lookup_url_kwarg: lookup_value} |
| 334 | return self.reverse(view_name, kwargs=kwargs, request=request, format=format) |
| 335 | |
| 336 | def to_internal_value(self, data): |
| 337 | request = self.context.get('request') |
no test coverage detected