Why __unicode__ doesn't work but __str__ does?

前端 未结 2 1448
心在旅途
心在旅途 2021-02-13 19:05

I\'m trying to break some rock by developing a website on my own, and I\'m starting by creating some registry pages and listing database records.

I\'m getting bugged wit

2条回答
  •  再見小時候
    2021-02-13 19:41

    If it's not the python 3 thing, your code as posted has incorrect indentation - not sure if copy/pasting bug or if that's how it is in the code. But your User model's methods need to be indented, like so:

    from django.db import models
    
    class User(models.Model):
        username = models.CharField(max_length=200)
        reg_date = models.DateTimeField('registry date')
    
        def __unicode__(self):
            return self.username
    

提交回复
热议问题