I need to hide some fields from a Form on Django Admin if the logged user is not a super user. This is what I came up with:
def get_form(self, request, obj=None, **kwargs):
form = super(RestauranteAdmin, self).get_form(request, obj, **kwargs)
if not request.user.is_superuser:
form.base_fields.pop('approved')
form.base_fields.pop('day_of_the_week')
form.base_fields.pop('photo')
form.label_suffix = ''
return form
This does indeed hide the necessary fields, but for some reason the admin also stops rendering my inlines if the user is not a super user. As far as I can see this method should have nothing to do with the inlines. Am I missing something?
Thanks,
Just exclude it before calling the parent method
Hope it helps