I am using Python 2.7 and Django 1.9.7. I am trying to add a string method to models.py but I'm getting an error. When I run "python manage.py runserver", I get the following:
ValueError: @python_2_unicode_compatible cannot be applied to Languages because it doesn't define __ str__().
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Languages(models.Model):
langid = models.AutoField(db_column='LangID', primary_key=True)
lname = models.CharField(db_column='lName', max_length=50, blank=True, null=True)
class Meta:
db_table = 'languages'
def __str__(self):
return self.lname
This is very similar to the following Question: python_2_unicode_compatible error
But the problem there was that Django was not a new enough version. Clearly there is something different going on here. Any ideas on what the problem might be?