Skip to content

Commit

Permalink
Remove problems from OriginTag's and OriginInfoValue's admin (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane authored May 15, 2024
1 parent cad153a commit 2e63f98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions oioioi/problems/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class OriginTagLocalizationInline(BaseTagLocalizationInline):

class OriginTagAdmin(BaseTagAdmin):
inlines = (OriginTagLocalizationInline,)
exclude = ['problems']

def formfield_for_manytomany(self, db_field, request, **kwargs):
_update_queryset_if_problems(db_field, **kwargs)
Expand Down Expand Up @@ -336,6 +337,7 @@ class OriginInfoValueLocalizationInline(BaseTagLocalizationInline):
class OriginInfoValueAdmin(admin.ModelAdmin):
form = OriginInfoValueForm
inlines = (OriginInfoValueLocalizationInline,)
exclude = ['problems']

def formfield_for_manytomany(self, db_field, request, **kwargs):
_update_queryset_if_problems(db_field, **kwargs)
Expand Down
9 changes: 5 additions & 4 deletions oioioi/problems/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ def save(self, commit=True):
category = self.cleaned_data['category']
parent_tag = category.parent_tag
instance.parent_tag = parent_tag
problems = self.cleaned_data.get('problems').prefetch_related('origintag_set')
for problem in problems:
if parent_tag not in problem.origintag_set.all():
parent_tag.problems.add(problem)
if 'problems' in self.cleaned_data:
problems = self.cleaned_data.get('problems').prefetch_related('origintag_set')
for problem in problems:
if parent_tag not in problem.origintag_set.all():
parent_tag.problems.add(problem)

if commit:
instance.save()
Expand Down

0 comments on commit 2e63f98

Please sign in to comment.