From 5523fb7e7413338807452a1aa8af55c8410a4059 Mon Sep 17 00:00:00 2001 From: Evan Zhang Date: Sun, 10 May 2020 16:16:18 -0400 Subject: [PATCH] Fix BlogPost admin page crashing when user only has view permission (#1382) --- judge/admin/interface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/judge/admin/interface.py b/judge/admin/interface.py index ffc4eee2c7..30a359ba83 100644 --- a/judge/admin/interface.py +++ b/judge/admin/interface.py @@ -54,7 +54,9 @@ class FlatPageAdmin(VersionAdmin, OldFlatPageAdmin): class BlogPostForm(ModelForm): def __init__(self, *args, **kwargs): super(BlogPostForm, self).__init__(*args, **kwargs) - self.fields['authors'].widget.can_add_related = False + if 'authors' in self.fields: + # self.fields['authors'] does not exist when the user has only view permission on the model. + self.fields['authors'].widget.can_add_related = False class Meta: widgets = {