我在 Django 项目上遇到了麻烦。Python 2.7、apache 2.2、mysql 数据库;这是models.py的代码
from django.db import models
from django.contrib import admin
class Item(models.Model):
name = models.CharField(max_length=150)
description = models.TextField()
class Meta:
ordering = ['name']
def __unicode__(self):
return self.name
def get_absolute_url(self):
return 'item_detail', None, {'object_id': self.id}
class Photo(models.Model):
item = models.ForeignKey('Item')
title = models.CharField(max_length=100)
image = models.ImageField(upload_to='photos')
caption = models.CharField(max_length=250, blank=True)
class Meta:
ordering = ['title']
def __unicode__(self):
return self.title
def get_absolute_url(self):
return 'photo_detail', None, {'object_id': self.id}
class PhotoInline(admin.StackedInline):
model = Photo
class ItemAdmin(admin.ModelAdmin):
inlines = [PhotoInline]
admin.site.register(Item, ItemAdmin)
admin.site.register(Photo)
当我尝试在管理面板中创建对象项时,它给了我一个错误
POST
Request URL: http://127.0.0.1/admin/item/item/add/
Django Version: 1.4.2
Exception Type: Warning
Exception Value:
'Photo' object has no attribute 'name'
Exception Location: C:\wamp\python27\lib\site-packages\MySQLdb\cursors.py in _warning_check, line 117
Python Executable: C:\wamp\bin\apache\apache2.2.22\bin\httpd.exe
Python Version: 2.7.0
Python Path:
['C:\\wamp\\python27\\lib\\site-packages\\setuptools-1.1.6-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\jaraco.develop-2.3-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\jaraco.windows-2.15-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\path.py-4.3-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\keyring-3.1-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\jaraco.util-8.5-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\six-1.4.1-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\ipython-1.1.0-py2.7.egg',
'C:\\wamp\\python27\\lib\\site-packages\\pyreadline-2.0-py2.7-win-amd64.egg',
'C:\\WINDOWS\\SYSTEM32\\python27.zip',
'C:\\wamp\\python27\\Lib',
'C:\\wamp\\python27\\DLLs',
'C:\\wamp\\python27\\Lib\\lib-tk',
'C:\\wamp\\bin\\apache\\apache2.2.22',
'C:\\wamp\\bin\\apache\\apache2.2.22\\bin',
'C:\\wamp\\python27',
'C:\\wamp\\python27\\lib\\site-packages',
'c:/DjangoProjects/photogallery/']
Server time: Thu, 24 Oct 2013 23:29:33 +0400
我应该怎么处理这个错误?