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.

def get_url(self, obj, view_name, request, format):
        """
        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.
        """
        # Unsaved objects will not yet have a valid URL.
        if obj.pk is None:
            return None

        lookup_value = getattr(obj, self.lookup_field)
        lookup_kwargs = {
            self.lookup_field: lookup_value,
        }

        # Try to lookup parent attr
        parent_lookup_value = None
        for attr in self.parent_lookup_field.split("__"):
            if not hasattr(obj, attr):
                break
            parent_lookup_value = getattr(parent_lookup_value or obj, attr)
        if parent_lookup_value:
            lookup_kwargs.update({self.parent_lookup_field: parent_lookup_value})

        return self.reverse(view_name, kwargs=lookup_kwargs, request=request, format=format)