From ce0aa9fdba591b1cdd75e73768259ef8ec1a1cf5 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Mon, 15 Feb 2021 15:10:03 +0100
Subject: [PATCH 2/3] django22: on_delete on ForeignKey and OneToOne fields
 (#51125)

---
 .../migrations/0002_auto_20150413_0629.py                   | 5 +++--
 .../migrations/0004_auto_20150430_0326.py                   | 5 +++--
 .../migrations/0005_street.py                               | 3 ++-
 passerelle_montpellier_encombrants/models.py                | 6 +++---
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/passerelle_montpellier_encombrants/migrations/0002_auto_20150413_0629.py b/passerelle_montpellier_encombrants/migrations/0002_auto_20150413_0629.py
index 0b10786..a0ef66a 100644
--- a/passerelle_montpellier_encombrants/migrations/0002_auto_20150413_0629.py
+++ b/passerelle_montpellier_encombrants/migrations/0002_auto_20150413_0629.py
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
 from django.db import models, migrations
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('passerelle_montpellier_encombrants', '0001_initial'),
     ]
 
@@ -47,18 +48,18 @@ class Migration(migrations.Migration):
                 ),
             ],
             options={},
             bases=(models.Model,),
         ),
         migrations.AddField(
             model_name='commune',
             name='sector',
-            field=models.ForeignKey(to='passerelle_montpellier_encombrants.Sector'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='passerelle_montpellier_encombrants.Sector'),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='collectday',
             name='sector',
-            field=models.ForeignKey(to='passerelle_montpellier_encombrants.Sector'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='passerelle_montpellier_encombrants.Sector'),
             preserve_default=True,
         ),
     ]
diff --git a/passerelle_montpellier_encombrants/migrations/0004_auto_20150430_0326.py b/passerelle_montpellier_encombrants/migrations/0004_auto_20150430_0326.py
index 624ce4d..0e5efc4 100644
--- a/passerelle_montpellier_encombrants/migrations/0004_auto_20150430_0326.py
+++ b/passerelle_montpellier_encombrants/migrations/0004_auto_20150430_0326.py
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
 from django.db import models, migrations
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('passerelle_montpellier_encombrants', '0003_sector_contact_email'),
     ]
 
@@ -19,17 +20,17 @@ class Migration(migrations.Migration):
             model_name='collectday',
             name='date',
             field=models.DateField(verbose_name='Date'),
             preserve_default=True,
         ),
         migrations.AlterField(
             model_name='collectday',
             name='sector',
-            field=models.ForeignKey(verbose_name='Sector', to='passerelle_montpellier_encombrants.Sector'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='Sector', to='passerelle_montpellier_encombrants.Sector'),
             preserve_default=True,
         ),
         migrations.AlterField(
             model_name='commune',
             name='insee',
             field=models.CharField(max_length=10, verbose_name='INSEE Code'),
             preserve_default=True,
         ),
@@ -37,12 +38,12 @@ class Migration(migrations.Migration):
             model_name='commune',
             name='name',
             field=models.CharField(max_length=50, verbose_name='Name'),
             preserve_default=True,
         ),
         migrations.AlterField(
             model_name='commune',
             name='sector',
-            field=models.ForeignKey(verbose_name='Sector', to='passerelle_montpellier_encombrants.Sector'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, verbose_name='Sector', to='passerelle_montpellier_encombrants.Sector'),
             preserve_default=True,
         ),
     ]
diff --git a/passerelle_montpellier_encombrants/migrations/0005_street.py b/passerelle_montpellier_encombrants/migrations/0005_street.py
index bcb3245..31fdaed 100644
--- a/passerelle_montpellier_encombrants/migrations/0005_street.py
+++ b/passerelle_montpellier_encombrants/migrations/0005_street.py
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
 from django.db import models, migrations
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('passerelle_montpellier_encombrants', '0004_auto_20150430_0326'),
     ]
 
@@ -14,14 +15,14 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name='Street',
             fields=[
                 (
                     'id',
                     models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True),
                 ),
                 ('name', models.CharField(max_length=128, verbose_name='Street')),
-                ('commune', models.ForeignKey(to='passerelle_montpellier_encombrants.Commune')),
+                ('commune', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='passerelle_montpellier_encombrants.Commune')),
             ],
             options={},
             bases=(models.Model,),
         ),
     ]
diff --git a/passerelle_montpellier_encombrants/models.py b/passerelle_montpellier_encombrants/models.py
index 115f6c3..8272b72 100644
--- a/passerelle_montpellier_encombrants/models.py
+++ b/passerelle_montpellier_encombrants/models.py
@@ -59,34 +59,34 @@ class Sector(models.Model):
             return '(%s)' % self.id
         return ', '.join([x.name for x in communes])
 
 
 @six.python_2_unicode_compatible
 class Commune(models.Model):
     name = models.CharField(max_length=50, blank=False, verbose_name=_('Name'))
     insee = models.CharField(max_length=10, blank=False, verbose_name=_('INSEE Code'))
-    sector = models.ForeignKey(Sector, verbose_name=_('Sector'))
+    sector = models.ForeignKey(Sector, verbose_name=_('Sector'), on_delete=models.CASCADE)
 
     def __str__(self):
         return u'%s (%s)' % (self.name, self.insee)
 
 
 @six.python_2_unicode_compatible
 class Street(models.Model):
-    commune = models.ForeignKey(Commune)
+    commune = models.ForeignKey(Commune, on_delete=models.CASCADE)
     name = models.CharField(max_length=128, blank=False, verbose_name=_('Street'))
 
     def __str__(self):
         return '%s, %s' % (self.name, self.commune)
 
 
 @six.python_2_unicode_compatible
 class CollectDay(models.Model):
-    sector = models.ForeignKey(Sector, verbose_name=_('Sector'))
+    sector = models.ForeignKey(Sector, verbose_name=_('Sector'), on_delete=models.CASCADE)
     date = models.DateField(verbose_name=_('Date'))
 
     class Meta:
         ordering = ['date']
         unique_together = ('sector', 'date')
 
     def __str__(self):
         return '%s: %s' % (self.date, self.sector)
-- 
2.30.0

