I'm brand new with django and sql. A tutorial I'm going through puts def __unicode__(self)
on every models class? here's the reference to the documentation But even after reading I still do not understand whats the purpose?
class Project(models.Model):
name = models.CharField(max_length=300)
def __unicode__(self):
return self.name
class Task(models.Model):
description = models.CharField(max_length=300)
project = models.ForeignKey(Project)
def __unicode__(self):
return self.description
The idea is when you print {{Project}} you get essentially just get a bunch of garbage that isn't really informative.
def __Unicode__(self):
This defines what you print so {{Project}} would display the description of the object. Which is much more useful, TO YOU.
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