Why use the __unicode __ (self) method for django 1.7+?

I am new to django and sql. The tutorial I'm looking at puts def __unicode__(self) in every model class? here is a link to the documentation But even after reading it, I still do not understand what is 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 
+6
source share
1 answer

The idea is that when you type {{Project}}, you get essentially just a bunch of garbage, which is not very informative.

 def __Unicode__(self): 

This determines what you type so that {{Project}} displays the description of the object. Which is much more useful for you.

+5
source

All Articles