Вопрос

I have a trouble with Django project. Python 2.7, apache 2.2, mysql database; This is code of 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)

when i try create object item in the admin panel it's give me an error

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

what should i do with this error?

Это было полезно?

Решение

I just tried your code snippet in one of my projects and it worked like a charm, i didn't see any problem in this, are you sure, you still getting this error. If so, Please check your database and see you have python path set for media in settings file.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top