vendredi 14 novembre 2014

modèles de Python 2.7 - django __unicode__ sans retour d'attribut - Stack Overflow


I've recently had this problem with my django site. When I go to view items in a app, the admin site crashes and I get this error report.


Error during template rendering

In template C:\Python27\lib\site-packages\django\contrib\admin\templates\admin\change_list.html, error at line 91

91 {% result_list cl %}


Exception Type: AttributeError at /admin/utils/anniversaryevent/
Exception Value: 'AnniversaryEvent' object has no attribute 'tx_name'

This is the class I'm calling.


class AnniversaryEvent(models.Model):

id_anniversaryevent = models.AutoField(primary_key=True, db_column='id_anniversaryevent')
tx_name = models.CharField(max_length=255L, unique=True, db_column='tx_name', name='Anniversary event')

def __unicode__(self):
return self.tx_name

The site was working fine until I changed the attribute name to tx_name (I've rebuilt the database to reflect the change).


I'm quite new to Django so I'm sorry if this is a completely obvious problem. Any help or information would be appropriated, thanks.


EDIT:


Iain Shelvington's suggestion worked. Thanks mate.


My admin.py for utils is


from django.contrib import admin
from utils.models import AnniversaryEvent
from utils.models import Category
from utils.models import Country
from utils.models import EventType
from utils.models import Location

admin.site.register(AnniversaryEvent)
admin.site.register(Category)
admin.site.register(Country)
admin.site.register(EventType)
admin.site.register(Location)


I've recently had this problem with my django site. When I go to view items in a app, the admin site crashes and I get this error report.


Error during template rendering

In template C:\Python27\lib\site-packages\django\contrib\admin\templates\admin\change_list.html, error at line 91

91 {% result_list cl %}


Exception Type: AttributeError at /admin/utils/anniversaryevent/
Exception Value: 'AnniversaryEvent' object has no attribute 'tx_name'

This is the class I'm calling.


class AnniversaryEvent(models.Model):

id_anniversaryevent = models.AutoField(primary_key=True, db_column='id_anniversaryevent')
tx_name = models.CharField(max_length=255L, unique=True, db_column='tx_name', name='Anniversary event')

def __unicode__(self):
return self.tx_name

The site was working fine until I changed the attribute name to tx_name (I've rebuilt the database to reflect the change).


I'm quite new to Django so I'm sorry if this is a completely obvious problem. Any help or information would be appropriated, thanks.


EDIT:


Iain Shelvington's suggestion worked. Thanks mate.


My admin.py for utils is


from django.contrib import admin
from utils.models import AnniversaryEvent
from utils.models import Category
from utils.models import Country
from utils.models import EventType
from utils.models import Location

admin.site.register(AnniversaryEvent)
admin.site.register(Category)
admin.site.register(Country)
admin.site.register(EventType)
admin.site.register(Location)

0 commentaires:

Enregistrer un commentaire