Not an admin expert here.

You are modifying the modeladmin instance and, by the behavior you're
describing, it looks like it is a global (shared) object. I'm guessing, you
can confirm this by printing id(self) in add_view(). I'll bet you get the
same value in each request, so the instance is shared, so the change is
visible (persisted) across request boundaries.

You may think about adding self.exclude = () in the else branch in order to
not exclude anything. Don't do that, you may end up leaking private
information to dgp if both root and dgp are logged in at the same time.

Instead override the get_exclude method.

See
https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_exclude

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMDYoXbb42hpu3jAATXTwxPw9kO8XeZpLOczbNa-Bzw5QAdGuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to