Using Sqlite3 & Django 3.0.2 - I have searched high and low, but can’t find a way to add a verbose name to the id of a model.
Anyone have ideas, please?
Bruckner de Villiers
Mike,
I tried id = model.AutoField(verbose_name=”Ticket #”). Migrate didn’t like it – can’t have duplicate primaries. I suspect this is because the Bug model already exists.
What I am trying to achieve is an auto-increment field whereby every time a user logs a bug/suggestion/comment it writes a unique ticket number in the background, which is used as a reference for subsequent actions like Fixed, Close, WiP, etc. and as a ForeignKey in the Comment model. I couldn’t find anything meaningful for this functionality and so thought that the ‘id’ is already fit for purpose, but merely requires an explanatory field text.
Make sense?
Bruckner de Villiers
083 625 1086
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e3e9fe6.1c69fb81.7cda5.a2fdSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Thank you Jason. However, I get the following error - AssertionError: Model bugs.Bugs can't have more than one auto-generated field. Before adding the underlined bug_ticket field everything worked. Is the error because the model already exists and I am adding the AutoField?
My models.py:
class Bugs(models.Model):
FUNCTION_CHOICES = [
('C', 'Contacts'),
('E', 'Execs'),
('I', 'Sector/Industry'),
('G', 'General'),
('L', 'Clients'),
('O', 'Organisations'),
('P', 'Opportunities'),
('S', 'Account Type'),
('T', 'Training Material'),
('U', 'Currencies'),
]
BUGTYPE_CHOICES = [
('B', 'Bug'),
('C', 'Comment'),
('S', 'Suggestion'),
]
CLOSED_CHOICES = [
('N', 'No'),
('W', 'Work in Progress'),
('Y', 'Yes'),
]
bug_ticket = models.AutoField(primary_key=False)
bug_author = models.ForeignKey('auth.User', on_delete=models.CASCADE, verbose_name="Issue Author")
bug_title = models.CharField(max_length=200, verbose_name="Brief Description:")
bug_type = models.CharField(max_length=1, choices=BUGTYPE_CHOICES, verbose_name="Issue Type")
bug_function = models.CharField(max_length=1, default="G", choices=FUNCTION_CHOICES, verbose_name="Function")
bug_text = models.TextField()
bug_status = models.CharField(max_length=1, default="N", choices=CLOSED_CHOICES, verbose_name="Issue addressed?")
bug_created_date = models.DateTimeField(auto_now_add=True)
bug_published_date = models.DateTimeField(blank=True, null=True)
bug_update_date = models.DateTimeField(auto_now=True, verbose_name="Last Updated:")
class Meta:
verbose_name_plural="Bugs"
def publish(self):
self.published_date = timezone.now()
self.save()
def approve_comments(self):
return self.comments.filter(approved_comment=True)
def get_absolute_url(self):
print(self.pk)
return reverse("bugs/bug_detail",kwargs={'pk':self.pk})
def __str__(self):
return self.bug_title
Thanks for your attention to date.
Bruckner de Villiers
083 625 1086
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3f0ecd5b-9493-47dd-bf85-382e87c3efd9%40googlegroups.com.