У меня есть два разных приложения Django, один из которых - fileUpload
. В File Upload я добавил Generic Relation как:NameError: name 'FileAttachment' не определен
from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
class FileAttachment(models.Model):
file = models.FileField(upload_to='fileuploads/%Y-%m-%d/')
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
attachee = generic.GenericForeignKey()
В моем другом приложении под названием XYZ
я добавил следующее обратное родовое отношение в models.py
attachment = generic.GenericRelation(FileAttachment)
Теперь, так что если я бегу manage.py syncdb
или любой другой команды управления , я получаю сообщение об ошибке: NameError: FileAttachment
В установленные приложения я следующие вещи:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.markup',
'django.contrib.humanize',
'south',
'taggit',
'taggit_autocomplete_modified',
'compressor',
'bootstrapform',
'fileupload',
'XYZ'
)
Оба приложения, XYZ
и fileupload
находятся на одинаковом корневом уровне.
Я использую Django 1.5 с python2.7
вы импортировали 'FileAttachment' в XYZ/models.py' файл'? что-то вроде 'from fileUpload.models import FileAttachment' – karthikr