2013-10-24 73 views
0

我在Django項目中遇到了麻煩。 Python 2.7,apache 2.2,mysql數據庫; 這是models.pyDjango屬性錯誤

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 

我應該怎麼做這個錯誤?

+1

是否有可能您已經做了一些更改並忘記重新啓動apache? – oleg

+0

這是整個堆棧跟蹤? – karthikr

+0

你可以發佈你的'admin.py'嗎? –

回答

0

我剛剛在我的一個項目中試過了你的代碼片段,它的工作方式就像一個魅力,我沒有看到任何問題,你確定,你仍然得到這個錯誤。如果是這樣,請檢查您的數據庫,並看到你有設置文件中的媒體設置python路徑。

+0

謝謝!問題出在媒體路徑上 –