On 23/04/2019 9:22 pm, Balaji Shetty wrote:
Hi

Did you get any particular solution. I am also facing the same problem. My project also have same requirement.

I think this problem must have been faced by every dveloper.

Can you please share the solution or any useful internet resource .

I noticed the message was mangled so I have reformatted the worst bits ...

def get_user_company(request): 
    """Return the company of which the user is a member. 

    Company is kept in the UserProfile fk company. Typically used 
    in get_queryset.filter() calls made in various places  to restrict
    a user's view to things owned by that user's company. 
    """

    profile = ""
    if profile: 
        try: 
            return profile.company
        except Exception: 
            # happens on deleting the company
            pass


def get_userprofile(request):
    """Return the userprofile from a user or request"""
    from company.models import UserProfile  # avoid circular imports

    if isinstance(request, User):
        usr = request 
    else: 
        usr = request.user
    if usr: 
        try: 
            return UserProfile.objects.get(user=usr)
        except Exception:
            # happens on deleting the user
            pass

And determining which fields are readonly depending on group membership is a matter of writing a callable which replaces ModelAdmin.get_readonly_fields and for which you need ...

def is_member(user, name):
    return user.groups.filter(name=name).exists() # or user.is_superuser

hth




And determining which fields are readonly depending on group membership is a matter of writing a callable which replaces ModelAdmin.get_readonly_fields and for which you need ...

def is_member(user, name): return user.groups.filter(name=name).exists() # or user.is_superuser

hth




On Sun, Apr 21, 2019 at 4:37 PM Joel Mathew <j...@eyrie.in <mailto:j...@eyrie.in>> wrote:

Thanks a lot, guys.

On Sun, 21 Apr, 2019, 3:58 PM Jani Tiainen, <rede...@gmail.com
<mailto:rede...@gmail.com>> wrote:

Hi,

We do in our applications pretty much same approach as Mike
proposed in his post. It's relatively efficient and works for
both, UI and application side pretty well and doesn't require
building anything complex and pretty much everything you need
is already built-in in Django.



On Sun, Apr 21, 2019 at 5:12 AM Joel Mathew <j...@joel.su
<mailto:j...@joel.su>> wrote:

I have an application for a hospital. There, I should be
able to assign different roles like Doctor, Nurse,
Attender, Auxillary Nurse, Pharmacist, Store Manager etc,
each of would be having specific access to seperate areas
(views), with some having restricted access. In addition,
there are other hospitals who would be having no access to
another hospital's records. All of these permissions
should be customisable, and I should be able to create
additional roles and permission groups for specific areas
later (from within the application itself, in production).
What would be the best solution to use? Is there a
middleware which works well. I don't want to roll my own
if I will be reinventing the wheel.

Currently my application has no use permissions. But
access to specific hospitals is being restricted by a
model whoch stores hospital name, and user name.
Sincerely yours,

 Joel G Mathew

-- You received this message because you are subscribed to
the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to
django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to
django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at
https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAA%3Diw_9BrOEh4Ss3X0g_EnaFyp1XTXij5DoZvva_XxwKVzXsGQ%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAA%3Diw_9BrOEh4Ss3X0g_EnaFyp1XTXij5DoZvva_XxwKVzXsGQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.



-- Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.
-- You received this message because you are subscribed to the
Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to
django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAHn91od2vbV7F0WwAVp6Eppqmmd5-NgZciO_04Tm%3D9x9FSJyvQ%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAHn91od2vbV7F0WwAVp6Eppqmmd5-NgZciO_04Tm%3D9x9FSJyvQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAA%3Diw_-6cLiAfN1NHovdY4-Y_Wtz1KToMWW6zErNKAdXNOpm1w%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAA%3Diw_-6cLiAfN1NHovdY4-Y_Wtz1KToMWW6zErNKAdXNOpm1w%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.



-- /Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,/
*/SGGS Institute of Engineering & Technology, /Vishnupuri, Nanded.MH.India//*
*Official: bsshe...@sggs.ac.in <mailto:bsshe...@sggs.ac.in> *
*// Mobile: +91-9270696267*

-- You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAECSbOtdC_wg-ceB6-dvWcS6z%2BoWkwm%2BzunBW3GR_Kd0G3GsrA%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAECSbOtdC_wg-ceB6-dvWcS6z%2BoWkwm%2BzunBW3GR_Kd0G3GsrA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bfb4630d-88df-e586-d511-21b740d798b1%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to