|
@@ -45,7 +45,7 @@ class Item(models.Model):
|
|
|
help_text="préférable au n° de série si possible")
|
|
|
serial = models.CharField(
|
|
|
verbose_name='N° de série',
|
|
|
- max_length=250, blank=True, unique=True,
|
|
|
+ max_length=250, blank=True, null=True, unique=True,
|
|
|
help_text='ou toute autre référence unique)')
|
|
|
buy_date = models.DateField(verbose_name='date d’achat')
|
|
|
owner = models.ForeignKey(
|
|
@@ -56,12 +56,20 @@ class Item(models.Model):
|
|
|
help_text="dans le cas de matériel n'appartenant pas à l'association")
|
|
|
comment = models.TextField(verbose_name='commentaire', blank=True,
|
|
|
null=True)
|
|
|
-
|
|
|
+
|
|
|
objects = ItemQuerySet().as_manager()
|
|
|
|
|
|
def __unicode__(self):
|
|
|
return self.designation
|
|
|
|
|
|
+ def save(self, *args, **kwargs):
|
|
|
+ # workaround for unique=True, null=True
|
|
|
+ # see https://code.djangoproject.com/ticket/4136#comment:33
|
|
|
+ self.mac_address = self.mac_address or None
|
|
|
+ self.serial = self.serial or None
|
|
|
+
|
|
|
+ return super(Item, self).save(*args, **kwargs)
|
|
|
+
|
|
|
def get_current_loan(self):
|
|
|
"""
|
|
|
Returns the current Loan for this Item, if exists, or None.
|