Skip to content

Commit

Permalink
fixed to space delete
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Feb 16, 2024
1 parent 3fd3c8e commit ce32c20
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cookbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,18 @@ def safe_delete(self):
BookmarkletImport.objects.filter(space=self).delete()
CustomFilter.objects.filter(space=self).delete()

Property.objects.filter(space=self).delete()
PropertyType.objects.filter(space=self).delete()

Comment.objects.filter(recipe__space=self).delete()
Keyword.objects.filter(space=self).delete()
Ingredient.objects.filter(space=self).delete()
Food.objects.filter(space=self).delete()
Keyword.objects.filter(space=self).delete()

# delete food in batches because treabeard might fail to delete otherwise
while Food.objects.filter(space=self).count() > 0:
pks = Food.objects.filter(space=self).values_list('pk')[:200]
Food.objects.filter(pk__in=pks).delete()

Unit.objects.filter(space=self).delete()
Step.objects.filter(space=self).delete()
NutritionInformation.objects.filter(space=self).delete()
Expand All @@ -347,9 +355,11 @@ def safe_delete(self):
SupermarketCategory.objects.filter(space=self).delete()
Supermarket.objects.filter(space=self).delete()

InviteLink.objects.filter(space=self).delete()
UserFile.objects.filter(space=self).delete()
UserSpace.objects.filter(space=self).delete()
Automation.objects.filter(space=self).delete()
InviteLink.objects.filter(space=self).delete()
TelegramBot.objects.filter(space=self).delete()
self.delete()

def get_owner(self):
Expand Down Expand Up @@ -442,6 +452,7 @@ def save(self, *args, **kwargs):
self.use_fractions = FRACTION_PREF_DEFAULT

return super().save(*args, **kwargs)

def __str__(self):
return str(self.user)

Expand Down Expand Up @@ -985,7 +996,6 @@ class RecipeBook(ExportModelOperationsMixin('book'), models.Model, PermissionMod
filter = models.ForeignKey('cookbook.CustomFilter', null=True, blank=True, on_delete=models.SET_NULL)
order = models.IntegerField(default=0)


space = models.ForeignKey(Space, on_delete=models.CASCADE)
objects = ScopedManager(space='space')

Expand Down

0 comments on commit ce32c20

Please sign in to comment.