def coerce_path(self, path, method, view):
     """
     Coerce {pk} path arguments into the name of the model field,
     where possible. This is cleaner for an external representation.
     (Ie. "this is an identifier", not "this is a database primary key")
     """
     if not self.coerce_path_pk or "{pk}" not in path:
         return path
     model = getattr(getattr(view, "queryset", None), "model", None)
     if model:
         field_name = get_pk_name(model)
     else:
         field_name = "id"
     return path.replace("{pk}", "{%s}" % field_name)
示例#2
0
    def coerce_path(self, path, method, view):
        """
        Coerce {pk} path arguments into the name of the model field,
        where possible. This is cleaner for an external representation.
        (Ie. "this is an identifier", not "this is a database primary key")
        """
        if not self.coerce_path_pk or '{pk}' not in path:
            return path

        model = getattr(getattr(view, 'queryset', None), 'model', None)
        if model:
            field_name = get_pk_name(model)
            path = path.replace('{pk}', '{%s}' % field_name)

        return path
示例#3
0
    def coerce_path(self, path, view):
        """Coerce {pk} path arguments into the name of the model field, where possible. This is cleaner for an
        external representation (i.e. "this is an identifier", not "this is a database primary key").

        :param str path: the path
        :param rest_framework.views.APIView view: associated view
        :rtype: str
        """
        if '{pk}' not in path:
            return path

        model = getattr(get_queryset_from_view(view), 'model', None)
        if model:
            field_name = get_pk_name(model)
        else:
            field_name = 'id'
        return path.replace('{pk}', '{%s}' % field_name)