-
-
Save faisalmahmud/8df6cc404ca01a27bd7e1d5a687a3863 to your computer and use it in GitHub Desktop.
Making a field in a django admin form visible or invisible depending on the user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from books.models import Agent, PolicyIssue | |
class PolicyIssueAdmin(admin.ModelAdmin): | |
def add_view(self, request, form_url='', extra_context=None): | |
if request.user.get_profile().is_employee: | |
self.model.branch.field.editable = False | |
else: | |
self.model.branch.field.editable = True | |
return super(PolicyIssueAdmin, self).add_view(request, form_url) | |
admin.site.register(PolicyIssue, PolicyIssueAdmin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment