MAJ : add on_delete + MIDDLEWARE
This commit is contained in:
parent
7c7adab658
commit
b45d7722a7
5 changed files with 44 additions and 33 deletions
|
@ -20,7 +20,10 @@ class Subscription(models.Model):
|
|||
|
||||
|
||||
class UserSubscription(Subscription):
|
||||
user = models.ForeignKey(User)
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
is_unsub = models.BooleanField(
|
||||
_("désinscription"),
|
||||
default=False
|
||||
|
@ -32,7 +35,10 @@ class UserSubscription(Subscription):
|
|||
|
||||
|
||||
class GroupSubscription(Subscription):
|
||||
group = models.ForeignKey(Group)
|
||||
group = models.ForeignKey(
|
||||
Group,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("souscription en groupe")
|
||||
|
|
|
@ -7,7 +7,6 @@ from django.db.models import Q
|
|||
|
||||
from .fields import IdField
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
from datetime import date
|
||||
|
||||
|
||||
|
@ -21,6 +20,7 @@ class EquipmentCategory(models.Model):
|
|||
blank=True,
|
||||
null=True,
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="children",
|
||||
help_text=_("merci de ne pas faire de référence cyclique"),
|
||||
verbose_name=_("parent"),
|
||||
|
@ -35,7 +35,6 @@ class EquipmentCategory(models.Model):
|
|||
return True
|
||||
current = current.parent
|
||||
|
||||
|
||||
def full_name(self):
|
||||
current = self
|
||||
res = ""
|
||||
|
@ -51,7 +50,6 @@ class EquipmentCategory(models.Model):
|
|||
full_name.short_description = _("Chemin complet")
|
||||
full_name_p = property(full_name)
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("catégories")
|
||||
verbose_name_plural = _("catégories")
|
||||
|
@ -67,7 +65,7 @@ class EquipmentCategory(models.Model):
|
|||
if current.parent == self:
|
||||
self.parent = None
|
||||
done = True
|
||||
elif current.parent == None:
|
||||
elif current.parent is None:
|
||||
done = True
|
||||
current = current.parent
|
||||
return super().save(*args, **kwargs)
|
||||
|
@ -76,7 +74,8 @@ class EquipmentCategory(models.Model):
|
|||
class EquipmentQuerySet(models.QuerySet):
|
||||
def in_category(self, cat):
|
||||
filtre = Q(id__lt=0)
|
||||
childs_id = [ c.id for c in EquipmentCategory.objects.all() if c.has_parent(cat) ]
|
||||
childs_id = [c.id for c in EquipmentCategory.objects.all()
|
||||
if c.has_parent(cat)]
|
||||
for pk in childs_id:
|
||||
filtre |= Q(category__id=pk)
|
||||
return self.filter(filtre)
|
||||
|
@ -102,6 +101,7 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
verbose_name=_("propriétaire"),
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
category = models.ForeignKey(
|
||||
EquipmentCategory,
|
||||
|
@ -171,8 +171,6 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
stock_aviable_p = property(stock_aviable)
|
||||
stock_lost_p = property(stock_lost)
|
||||
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("matériel")
|
||||
verbose_name_plural = _("matériels")
|
||||
|
@ -195,6 +193,7 @@ class EquipmentAttribute(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class EquipmentAttributeValue(models.Model):
|
||||
equipment = models.ForeignKey(
|
||||
Equipment,
|
||||
|
@ -223,8 +222,15 @@ class EquipmentAttributeValue(models.Model):
|
|||
|
||||
|
||||
class EquipmentAttribution(models.Model):
|
||||
equipment = models.ForeignKey(Equipment, verbose_name=_("matériel"))
|
||||
activity = models.ForeignKey(Activity)
|
||||
equipment = models.ForeignKey(
|
||||
Equipment,
|
||||
verbose_name=_("matériel"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
activity = models.ForeignKey(
|
||||
Activity,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
amount = models.BigIntegerField(_("quantité attribuée"))
|
||||
remarks = models.TextField(
|
||||
_("remarques concernant l'attribution"),
|
||||
|
@ -241,7 +247,8 @@ class EquipmentAttribution(models.Model):
|
|||
self.activity.get_herited('title'))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.equipment.event and self.equipment.event != self.activity.event:
|
||||
if (self.equipment.event
|
||||
and self.equipment.event != self.activity.event):
|
||||
raise ValidationError
|
||||
|
||||
super(EquipmentAttribution, self).save(*args, **kwargs)
|
||||
|
|
|
@ -56,7 +56,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sites',
|
||||
|
||||
# 'channels',
|
||||
'rest_framework',
|
||||
# 'rest_framework',
|
||||
'bootstrapform',
|
||||
'widget_tweaks',
|
||||
'taggit',
|
||||
|
@ -71,8 +71,7 @@ INSTALLED_APPS = [
|
|||
'allauth_cas',
|
||||
'allauth_ens.providers.clipper',
|
||||
|
||||
|
||||
'api',
|
||||
# 'api',
|
||||
'communication',
|
||||
'equipment',
|
||||
'event',
|
||||
|
@ -80,7 +79,7 @@ INSTALLED_APPS = [
|
|||
'users',
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
@ -213,7 +212,5 @@ SOCIALACCOUNT_PROVIDERS = {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ACCOUNT_ADAPTER = 'shared.allauth_adapter.AccountAdapter'
|
||||
SOCIALACCOUNT_ADAPTER = 'shared.allauth_adapter.SocialAccountAdapter'
|
||||
|
|
|
@ -12,9 +12,9 @@ DEBUG = True
|
|||
|
||||
# Add some debugging tools
|
||||
INSTALLED_APPS += ["debug_toolbar", "debug_panel"] # NOQA
|
||||
MIDDLEWARE_CLASSES = (
|
||||
MIDDLEWARE = (
|
||||
["debug_panel.middleware.DebugPanelMiddleware"]
|
||||
+ MIDDLEWARE_CLASSES # NOQA
|
||||
+ MIDDLEWARE # NOQA
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ class EventSpecificMixin(models.Model):
|
|||
verbose_name=_("évènement"),
|
||||
help_text=_("Si spécifié, l'instance du modèle"
|
||||
"est spécifique à l'évènement en question"),
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue