Hi My project works on Django and some AngularJS. I want map my Django model field values into some custom string values. The following is my Model,
class History(models.Model):
TYPE_CHOICES = (
(1, 'CREATE'),
(0, 'EDIT'),
(2, 'DELETE'),
)
user = models.ForeignKey(User, related_name='+')
mw = models.ForeignKey('CP', related_name="history")
field_name = models.CharField(max_length=192, null=False)
old_value = models.CharField(max_length=500, null=True, blank=True)
new_value = models.CharField(max_length=500, null=True, blank=True)
type = models.IntegerField(default=0, choices=TYPE_CHOICES)
date_created = models.DateTimeField(auto_now_add=True)
the type 1, 2 and 0 I need to display in my website. So i just passed the value as <td>{{t.type}}</td>
But it giving me the values as 1, 2 and 0. How can I display it as create, update or delete string values? Any idea guys? Thanks in advance.
In your template change {{t.type}}
to {{ t.get_type_display }}
.
You can read about this in docs: get_FOO_display docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With