Skip to content

Commit

Permalink
Make sure delete operations work as expected for Polymorphic models
Browse files Browse the repository at this point in the history
While testing the PR, I discovered this bug because I couldn't delete
applications I've created. After doing some research, I figured out this
is due to a known bug on django-polymorphic. More on this issue can be
found in this issue:

jazzband/django-polymorphic#229
  • Loading branch information
berinhard committed Jan 13, 2022
1 parent 0801976 commit dac3158
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sponsors/models/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def list_advertisables(self):

class BenefitFeatureQuerySet(PolymorphicQuerySet):

def delete(self):
if not self.polymorphic_disabled:
return self.non_polymorphic().delete()
else:
return super().delete()

def from_sponsorship(self, sponsorship):
return self.filter(sponsor_benefit__sponsorship=sponsorship).select_related("sponsor_benefit__sponsorship")

Expand Down
4 changes: 4 additions & 0 deletions sponsors/models/sponsors.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,9 @@ def name_for_display(self):
name = feature.display_modifier(name)
return name

def delete(self):
self.features.all().delete()
super().delete()

class Meta(OrderedModel.Meta):
pass

0 comments on commit dac3158

Please sign in to comment.