unicode (self) does not work for me. I still see the "Name of the object" in the admin. My code is as follows:
import datetime # standard python datetime module from django.db import models # Djangos time-zone-related utilities from django.utils import timezone class Name(models.Model): name = models.CharField(max_length=200) def __unicode__(self): # Python 3: def __str__(self): return self.name
Thank you
The problem is that you need to define the __unicode__ method in the class definition.
__unicode__
import datetime # standard python datetime module from django.db import models # Djangos time-zone-related utilities from django.utils import timezone class Name(models.Model): name = models.CharField(max_length=200) def __unicode__(self): # Python 3: def __str__(self): return str(self.name)
should work for you.
Python INDENTION will respond most of the time, work with correlation, use an editor, or select _unicode_ (self) with a tab
def __unicode__(self): # Python 3: def __str__(self): return str(self.name)
Source: https://habr.com/ru/post/1479476/More articles:Is it possible to use the same Yammer API key on multiple networks - apiDefining a function using a typedef function in C ++ - c ++What happens with this CSS3? I can not find it - htmlRead and then write .pcm files using Java - javaIs $ (this) required with the standard jQuery plugin template - javascriptAndroid: a great way to clear all activity on logout? - androidCan Python __set__ handle ever be called with instance = No? - pythonWhen will it finally be fulfilled? - javaSphinx documentation: ongoing numbering from header to list - python-sphinxHow to display array in php matrix table - phpAll Articles