Browse Source

django 2.0

Élie Bouttier 7 years ago
parent
commit
24a28d852b

+ 1 - 1
accounts/models.py

@@ -6,7 +6,7 @@ from adhesions.models import Adhesion, User, Corporation
 
 
 class Profile(models.Model):
-    user = models.OneToOneField(User, related_name='profile', verbose_name='Utilisateur')
+    user = models.OneToOneField(User, related_name='profile', verbose_name='Utilisateur', on_delete=models.CASCADE)
     phone_number = models.CharField(max_length=16, blank=True, default='',
                                     verbose_name='Numéro de téléphone')
     address = models.TextField(blank=True, default='', verbose_name='Adresse')

+ 1 - 1
adhesions/admin.py

@@ -6,7 +6,7 @@ from django.contrib.auth.models import User as AuthUser
 from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
 from django.http import HttpResponseRedirect
 from django.utils.html import format_html, mark_safe
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.utils import timezone
 
 from .forms import UserCreationForm

+ 1 - 1
adhesions/middleware.py

@@ -9,7 +9,7 @@ class CorporationMiddleware:
         self.get_response = get_response
 
     def __call__(self, request):
-        if request.user.is_authenticated():
+        if request.user.is_authenticated:
             if 'corporations' not in request.session:
                 corporations = Corporation.objects.filter(members=request.user)
                 request.session['corporations'] = serializers.serialize('json', corporations, fields=('pk', 'social_reason',))

+ 3 - 3
adhesions/models.py

@@ -3,7 +3,7 @@ from django.urls import reverse
 from django.contrib.auth.models import User as AuthUser
 from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
 from django.contrib.contenttypes.models import ContentType
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.utils.html import format_html
 
 from djadhere.utils import get_active_filter
@@ -82,8 +82,8 @@ class Adhesion(models.Model):
     notes = models.TextField(blank=True, default='')
     active_legacy = models.NullBooleanField(default=None, verbose_name='Adhésion en cours')
 
-    user = models.OneToOneField(User, null=True)
-    corporation = models.OneToOneField(Corporation, null=True)
+    user = models.OneToOneField(User, null=True, on_delete=models.PROTECT)
+    corporation = models.OneToOneField(Corporation, null=True, on_delete=models.PROTECT)
 
     membership = models.OneToOneField(RecurringPayment, on_delete=models.CASCADE)
 

+ 1 - 1
banking/admin.py

@@ -1,6 +1,6 @@
 from django.contrib import admin
 from django.db import models
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.forms import BaseInlineFormSet
 from django.utils.html import format_html
 from django.conf.urls import url

+ 1 - 1
banking/models.py

@@ -1,7 +1,7 @@
 from django.db import models
 from django.core.validators import MinValueValidator, MaxValueValidator
 from django.core.exceptions import ValidationError
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 
 
 class CurrentPaymentManager(models.Manager):

+ 1 - 1
banking/utils.py

@@ -1,4 +1,4 @@
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.conf import settings
 
 from djadhere.utils import send_notification

+ 1 - 1
requirements.txt

@@ -1,4 +1,4 @@
-django<1.12
+django<2.1
 django-bootstrap3
 django-leaflet
 django-geojson

+ 2 - 2
services/admin.py

@@ -3,7 +3,7 @@ from django.db import models
 from django.db.models import Q
 from django.forms import ModelForm, BaseInlineFormSet
 from django.utils import timezone
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.utils.html import format_html
 from django.core.mail import mail_managers
 from django.conf.urls import url
@@ -269,7 +269,7 @@ class SwitchPortInline(PortInline):
 
     def get_queryset(self, request):
         qs = super().get_queryset(request)
-        qs = qs.prefetch_related('switch', 'service', 'service__service_type')
+        qs = qs.select_related('switch', 'service', 'service__service_type')
         return qs
 
 

+ 1 - 1
services/models.py

@@ -188,7 +188,7 @@ class Antenna(models.Model):
                 RegexValidator(r'^([0-9a-fA-F]{2}([:-]?|$)){6}$'),
             ],
             verbose_name='Adresse MAC')
-    contact = models.ForeignKey(Adhesion, null=True, blank=True)
+    contact = models.ForeignKey(Adhesion, null=True, blank=True, on_delete=models.PROTECT)
     notes = models.TextField(blank=True)
     position = geo_models.PointField(null=True, blank=True)
     orientation = models.IntegerField(verbose_name='Orientation (°)', null=True, blank=True)

+ 1 - 1
services/utils.py

@@ -1,4 +1,4 @@
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.conf import settings
 
 from djadhere.utils import send_notification

+ 3 - 3
stocking/models.py

@@ -5,7 +5,7 @@ from mptt.models import MPTTModel, TreeForeignKey
 
 class Category(MPTTModel):
     parent = TreeForeignKey("self", null=True, blank=True, related_name='children',
-                            db_index=True, verbose_name='catégorie parente')
+                            db_index=True, verbose_name='catégorie parente', on_delete=models.CASCADE)
     name = models.CharField(max_length=64)
 
     class MPTTMeta:
@@ -29,9 +29,9 @@ class Location(models.Model):
 
 
 class Equipment(models.Model):
-    category = TreeForeignKey(Category, verbose_name='catégorie')
+    category = TreeForeignKey(Category, verbose_name='catégorie', on_delete=models.CASCADE)
     quantity = models.PositiveIntegerField(default=0, verbose_name='quantité')
-    location = models.ForeignKey(Location, verbose_name='emplacement')
+    location = models.ForeignKey(Location, verbose_name='emplacement', on_delete=models.CASCADE)
 
     class Meta:
         verbose_name = 'Équipement'