From e34b95f592d6ac9a7a84840a7e7ef7f298729c7a Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Wed, 13 Apr 2022 15:57:21 +0200 Subject: [PATCH] Add __str__ method to have a better representation in admin interface --- asset/models.py | 6 ++++++ booker/models.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/asset/models.py b/asset/models.py index 396be05..ab40d8f 100644 --- a/asset/models.py +++ b/asset/models.py @@ -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 diff --git a/booker/models.py b/booker/models.py index fb7ea0e..af42c54 100644 --- a/booker/models.py +++ b/booker/models.py @@ -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) + ')'