2010-05-19 5 views
1

아래 파일이 있고 projectmanager라는 django 프로젝트의 일부인이 파일은 projectmanager/projects/models.py입니다. 파이썬 인터프리터를 사용하여 기능을 테스트하기 위해 프로젝트를 가져올 때마다 FileRepo()를 찾을 수 없다는 8 행의 이름 오류가 발생합니다. 이 수업을 올바르게 가져올 수 있습니까? 이상적으로 내가 찾고있는 것은 각 프로젝트에 각각 들어 있고 알려지지 않은 파일 수가 들어있는 여러 개의 FileRepos를 포함하는 것입니다. 사전에 도움을 주셔서 감사합니다.Python에서 동일한 파일 내의 다른 클래스로 클래스를 가져 오는 방법

#imports 
from django.db import models 
from django.contrib import admin 
#Project is responsible for ensuring that each project contains all of the folders and file storage 
#mechanisms a project needs, as well as a unique CCL# 
class Project(models.Model): 
    ccl = models.CharField(max_length=30) 
    Techpacks = FileRepo() 
    COAS = FileRepo() 
    Shippingdocs = FileRepo() 
    POchemspecs = FileRepo() 
    Internalpos = FileRepo() 
    Finalreports = FileRepo() 
    Batchrecords = FileRepo() 
    RFPS = FileRepo() 
    Businessdev = FileRepo() 
    QA = FileRepo() 
    Updates = FileRepo() 

    def __unicode__(self): 
     return self.ccl 

#ProjectFile is the file object used by each FileRepo component 
class ProjectFile(models.Model): 
    file = models.FileField(uploadto='ProjectFiles') 

    def __unicode__(self): 
     return self.file 

#FileRepo is the model for the "folders" to be used in a Project 
class FileRepo(models.Model): 
    typeOf = models.CharField(max_length=30) 
    files = models.ManyToManyField(ProjectFile) 

    def __unicode__(self): 
      return self.typeOf 

답변

0

전화하기 전에 FileRepo를 선언하셨습니까? IE, models.py 파일의 클래스 프로젝트보다 앞서 클래스 FileRepo를 이동 하시겠습니까?

+0

팁 주셔서 감사합니다. – Chris

3

일반적으로 McPeterson은 이름이 발견 될 때 위와 같이 사용되는 곳에서 정의되어야합니다. Django에서는 다른 클래스의 속성으로 클래스를 임의로 할당 할 수 없습니다. 그들 사이에 적절한 관계를 정의해야합니다. the documentation on relationship fields을 읽어 보시기 바랍니다.

+0

도움을 주셔서 감사합니다. 모델 정의가 실행되는 한 모두 원활하게 실행됩니다. – Chris

관련 문제