Add __str__ method to have a better representation in admin interface

This commit is contained in:
Dirk Jahnke 2022-04-13 15:57:21 +02:00
parent c7da144f5e
commit e34b95f592
2 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,9 @@ class Asset(models.Model):
def get_absolute_url(self):
return reverse('asset:detail', kwargs={'pk': self.pk})
def __str__(self):
return self.named_id + ' (' + str(self.quantity) + '): ' + self.description
class GtinProduct(models.Model):
gtin = models.CharField(max_length=40, unique=True)
@ -33,3 +36,6 @@ class GtinProduct(models.Model):
brand = models.CharField(max_length=40, blank=True)
created_ts = models.DateTimeField('datetime created', auto_now_add=True)
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
def __str__(self):
return self.gtin + ': ' + self.name

View File

@ -16,3 +16,6 @@ class Scanner(models.Model):
changed_ts = models.DateTimeField('datetime updated', auto_now=True)
changed_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_deleted_user),
related_name='changed_scanners')
def __str__(self):
return self.named_id + ': ' + self.description + ' (' + str(self.last_online_ts) + ')'