Skip to content

Instantly share code, notes, and snippets.

View ragsagar's full-sized avatar
🙂
⭐️ ⭐️ ⭐️ ⭐️ ⭐️ ⭐️

Rag Sagar.V ragsagar

🙂
⭐️ ⭐️ ⭐️ ⭐️ ⭐️ ⭐️
View GitHub Profile
@ragsagar
ragsagar / admin.py
Created May 9, 2012 17:19
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