Browse Source

Delete a member will not delete associated loans

instead, it will set its FK to NULL, keeping loan history intact (but partly
anonymized).

Ref #30 Ref #137
Jocelyn Delalande 6 years ago
parent
commit
286c69f4c3

+ 25 - 0
hardware_provisioning/migrations/0018_auto_20180819_0211.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('hardware_provisioning', '0017_item_deployed'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='item',
+            options={'ordering': ['designation', 'mac_address', 'serial'], 'verbose_name': 'objet'},
+        ),
+        migrations.AlterField(
+            model_name='loan',
+            name='user',
+            field=models.ForeignKey(related_name='loans', on_delete=django.db.models.deletion.SET_NULL, verbose_name='membre', to=settings.AUTH_USER_MODEL, null=True),
+        ),
+    ]

+ 3 - 2
hardware_provisioning/models.py

@@ -138,8 +138,9 @@ class LoanQuerySet(models.QuerySet):
 
 class Loan(models.Model):
     item = models.ForeignKey(Item, verbose_name='objet', related_name='loans')
-    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='membre',
-                             related_name='loans')
+    user = models.ForeignKey(
+        settings.AUTH_USER_MODEL, verbose_name='membre',
+        related_name='loans', null=True, on_delete=models.SET_NULL)
     loan_date = models.DateTimeField(verbose_name='date de prêt')
     loan_date_end = models.DateTimeField(verbose_name='date de fin de prêt',
                                      null=True, blank=True)