Giter Site home page Giter Site logo

Comments (3)

lefterisnik avatar lefterisnik commented on August 18, 2024

Hi @ciarancourtney, I can't find an easy way to determine this. Maybe, you could try the _has_change_only_permission method. I don't know exactly your case but you could have something like this:

def get_form(self, request, obj=None, **kwargs):
    form = super().get_form(request, obj, **kwargs)
    if self._has_change_only_permission(request, obj):
        return <the_form_that_you_want>

    return form

Hope, this helps you.

from django-admin-view-permission.

ciarancourtney avatar ciarancourtney commented on August 18, 2024

Does _has_change_only_permission() return False if user has view and change? If so I think I'd use has_change_permission(), as its typical to layer permission in order of privilege i.e. a view-only user has view perm, a change user has view and change, a full user has view, change, add delete and so on

from django-admin-view-permission.

lefterisnik avatar lefterisnik commented on August 18, 2024

The _has_change_only_permission runs underneath the super has_change_permission. So, if the user has change permission it will return True otherwise it will return False. In general if you want to determine that the view is view-only you need to have something like this:

if not self._has_change_only_permission(request, obj) and self.has_view_permission(request, obj)

from django-admin-view-permission.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.