Skip to content

Commit

Permalink
fix deletion of BenefitFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Dec 14, 2023
1 parent fad5f2b commit 7b14c6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sponsors/models/benefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

########################################
# Benefit features abstract classes
from sponsors.models.managers import BenefitFeatureQuerySet
from sponsors.models.managers import BenefitFeatureQuerySet, BenefitFeatureConfigurationQuerySet


########################################
Expand Down Expand Up @@ -307,11 +307,14 @@ class BenefitFeatureConfiguration(PolymorphicModel):
Base class for sponsorship benefits configuration.
"""

objects = BenefitFeatureQuerySet.as_manager()
benefit = models.ForeignKey("sponsors.SponsorshipBenefit", on_delete=models.CASCADE)
non_polymorphic = models.Manager()

class Meta:
verbose_name = "Benefit Feature Configuration"
verbose_name_plural = "Benefit Feature Configurations"
base_manager_name = 'non_polymorphic'

@property
def benefit_feature_class(self):
Expand Down
9 changes: 9 additions & 0 deletions sponsors/models/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ def provided_assets(self):
return self.instance_of(*provided_assets_classes).select_related("sponsor_benefit__sponsorship")


class BenefitFeatureConfigurationQuerySet(PolymorphicQuerySet):

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


class GenericAssetQuerySet(PolymorphicQuerySet):

def all_assets(self):
Expand Down

0 comments on commit 7b14c6c

Please sign in to comment.