Skip to content

Commit

Permalink
series references
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysquid committed Dec 10, 2023
1 parent eeba90e commit f91f90c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions inventory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Series(models.Model):
("comics", "comic"),
("novel", "roman")
]
id = models.CharField("référence", primary_key=True, max_length=5, validators=[
id = models.CharField("code", primary_key=True, max_length=5, validators=[
validators.RegexValidator('^[A-Z0-9]{5}$')
])
name = models.CharField("nom", max_length=255)
Expand All @@ -71,6 +71,11 @@ def nb_books(self):
return self.book_set.count()
nb_books.fget.short_description = "nombre de volumes"

@property
def reference(self):
return str(self.genre.id).zfill(2) + self.id
reference.fget.short_description = "référence"

def __str__(self):
return self.name

Expand Down Expand Up @@ -103,12 +108,7 @@ def __str__(self):
return f"{self.series} {self.volume_nb}"

def save(self, *args, **kwargs):
self.id = "".join((
str(self.series.genre.id).zfill(2),
self.series.id,
str(self.volume_nb).zfill(3),
str(self.duplicate_nb).zfill(2)
))
self.id = self.series.reference + str(self.volume_nb).zfill(3) + str(self.duplicate_nb).zfill(2)
super().save(*args, **kwargs)

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion inventory/templates/inventory/series_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2 class="mb-4">{{ series.name }}</h2>
</div>
<div>
<div class="text-body-secondary">Référence</div>
<div>{{ series.id }}</div>
<div>{{ series.reference }}</div>
</div>
</div>

Expand Down

0 comments on commit f91f90c

Please sign in to comment.