Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Set on_cascade=Null

Rolandab3137d4af97
diff --git a/wger/core/models.py b/wger/core/models.py
index d90f89188..cc1e2fa6c 100644
--- a/wger/core/models.py
+++ b/wger/core/models.py
@@ -131,7 +131,7 @@ class UserProfile(models.Model):
editable=False,
null=True,
blank=True,
- on_delete=models.CASCADE)
+ on_delete=models.SET_NULL)
'''
The gym this user belongs to, if any
'''
diff --git a/wger/gym/models.py b/wger/gym/models.py
index 02cb8d75a..715a323f4 100644
--- a/wger/gym/models.py
+++ b/wger/gym/models.py
@@ -94,17 +94,6 @@ class Gym(m.Model):
'''
return self.name
- def delete(self, using=None):
- '''
- Make sure that there are no users with this gym in their profiles
- '''
-
- # Not accessing the profile directly to avoid cyclic import problems
- for user in User.objects.filter(userprofile__gym=self).all():
- user.userprofile.gym = None
- user.userprofile.save()
- super(Gym, self).delete(using)
-
def get_absolute_url(self):
'''
Return the URL for this object
diff --git a/wger/gym/tests/test_gym.py b/wger/gym/tests/test_gym.py
index 8137404b5..8e6bf13ee 100644
--- a/wger/gym/tests/test_gym.py
+++ b/wger/gym/tests/test_gym.py
@@ -151,4 +151,4 @@ class GymTestCase(WorkoutManagerTestCase):
self.assertEqual(UserProfile.objects.filter(gym=gym).count(), 17)
gym.delete()
- self.assertEqual(UserProfile.objects.filter(gym=gym).count(), 0)
+ self.assertEqual(UserProfile.objects.filter(gym_id=1).count(), 0)