Skip to content

Instantly share code, notes, and snippets.

View faisalmahmud's full-sized avatar

Faisal Mahmud faisalmahmud

View GitHub Profile
@faisalmahmud
faisalmahmud / admin.py
Created March 8, 2022 18:12 — forked from ragsagar/admin.py
Making a field in a django admin form visible or invisible depending on the user
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