Skip to content

Commit 634040f

Browse files
committed
Merge pull request #150 from pivotal-energy-solutions/on_delete_set_null
Do NOT CASCADE delete the history elements when a user gets deleted.
2 parents 04888fe + db94da5 commit 634040f

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Authors
2222
- Micah Denbraver
2323
- Rajesh Pappula
2424
- Ross Lote
25+
- Steven Klass
2526
- Trey Hunner
2627
- Ulysses Vilela
2728
- vnagendra

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
=======
33

4+
1.5.x (YYYY-MM-DD)
5+
------------------
6+
- Do NOT delete the history elements when a user is deleted.
7+
48
1.5.3 (2014-11-18)
59
------------------
610
- Fix migrations while using ``order_with_respsect_to`` (gh-140)

simple_history/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def get_instance(self):
160160
'history_id': models.AutoField(primary_key=True),
161161
'history_date': models.DateTimeField(),
162162
'history_user': models.ForeignKey(
163-
user_model, null=True, related_name=self.user_related_name),
163+
user_model, null=True, related_name=self.user_related_name,
164+
on_delete=models.SET_NULL),
164165
'history_type': models.CharField(max_length=1, choices=(
165166
('+', 'Created'),
166167
('~', 'Changed'),

simple_history/tests/tests/test_admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,19 @@ def test_other_admin(self):
219219
self.app.get(history_url)
220220
change_url = get_history_url(state, 0, site="other_admin")
221221
self.app.get(change_url)
222+
223+
def test_deleteting_user(self):
224+
"""Test deletes of a user does not cascade delete the history"""
225+
self.login()
226+
poll = Poll(question="why?", pub_date=today)
227+
poll._history_user = self.user
228+
poll.save()
229+
230+
historical_poll = poll.history.all()[0]
231+
self.assertEqual(historical_poll.history_user, self.user)
232+
233+
self.user.delete()
234+
235+
historical_poll = poll.history.all()[0]
236+
self.assertEqual(historical_poll.history_user, None)
237+

0 commit comments

Comments
 (0)