1 ) Disable Add button in django admin interface for some models if they are having data in that table .
Answer :
Add below function in admin.py file in your respective class .
def has_add_permission(self,request):
count = Data.objects.all().count()
if count > 0:
return False
else:
return True
2 ) disable delete operation for some models in django admin interface.
def has_delete_permission(self, request, obj=None):
return False
3 ) Add link in django admin Interface .
list_display = ['my_url_field']
def my_url_field(self, obj):
return '<a href="%s%s">%s</a>' % ('', obj.id, 'Click Here')
my_url_field.allow_tags = True
my_url_field.short_description = 'Data'
No comments:
Post a Comment