(permission)
return has_permission
This is actually a permission check factory. It means that it will return
    a function that can then act as a permission check. The returned callable
    will check if the user has the with ``permission`` provided model
    permission. You can use ``{app_label}`` and ``{model_name}`` as
    placeholders in the permission name. They will be replaced with the
    ``app_label`` and the ``model_name`` (in lowercase) of the model that the
    current view is operating on.

    Example:

    .. code-block:: python

        check_add_perm = model_permission('{app_label}.add_{model_name}')

        class ModelAddPermission(permissions.BasePermission):
            permissions = [check_add_perm]
This is actually a permission check factory. It means that it will return
    a function that can then act as a permission check. The returned callable
    will check if the user has the with ``permission`` provided model
    permission. You can use ``{app_label}`` and ``{model_name}`` as
    placeholders in the permission name. They will be replaced with the
    ``app_label`` and the ``model_name`` (in lowercase) of the model that the
    current view is operating on.
This is actually a permission check factory . It means that it will return a function that can then act as a permission check . The returned callable will check if the user has the with permission provided model permission . You can use { app_label } and { model_name } as placeholders in the permission name . They will be replaced with the app_label and the model_name ( in lowercase ) of the model that the current view is operating on .
def model_permission(permission):
    '''
    This is actually a permission check factory. It means that it will return
    a function that can then act as a permission check. The returned callable
    will check if the user has the with ``permission`` provided model
    permission. You can use ``{app_label}`` and ``{model_name}`` as
    placeholders in the permission name. They will be replaced with the
    ``app_label`` and the ``model_name`` (in lowercase) of the model that the
    current view is operating on.

    Example:

    .. code-block:: python

        check_add_perm = model_permission('{app_label}.add_{model_name}')

        class ModelAddPermission(permissions.BasePermission):
            permissions = [check_add_perm]
    '''
    def has_permission(request, view, obj=None):
        model_class = getattr(view, 'model', None)
        queryset = getattr(view, 'queryset', None)

        if model_class is None and queryset is not None:
            model_class = queryset.model

        assert model_class, (
            'Cannot apply model permissions on a view that does not '
            'have a `.model` or `.queryset` property.')

        try:
            # django 1.8+
            model_name = model_class._meta.model_name
        except AttributeError:
            model_name = model_class._meta.module_name

        permission_name = permission.format(
            app_label=model_class._meta.app_label,
            model_name=model_name)
        return request.user.has_perm(permission_name, obj)
    return has_permission
def model_permission ( permission ) : def has_permission ( request , view , obj = None ) : model_class = getattr ( view , 'model' , None ) queryset = getattr ( view , 'queryset' , None ) if model_class is None and queryset is not None : model_class = queryset . model assert model_class , ( 'Cannot apply model permissions on a view that does not ' 'have a `.model` or `.queryset` property.' ) try : # django 1.8+ model_name = model_class . _meta . model_name except AttributeError : model_name = model_class . _meta . module_name permission_name = permission . format ( app_label = model_class . _meta . app_label , model_name = model_name ) return request . user . has_perm ( permission_name , obj ) return has_permission