2010-05-19 254 views
1

我有以下文件,它是名为projectmanager的django项目的一部分,此文件为projectmanager/projects/models.py。每当我使用Python解释器来导入一个项目只是为了测试功能,我得到了第8行的名称错误,无法找到FileRepo()。如何正确导入这些类?理想情况下,我正在寻找的是每个Project包含多个FileRepos,每个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,移动类FileRepo提前在models.py文件中的类项目?

+0

感谢您的提示。 – Chris 2010-05-19 19:43:12

3

尽管McPeterson的名字一般都是正确的,但它必须在使用它的地方定义,在你的情况下,它不会帮助。在Django中,您不能任意指定类作为其他类的属性。你需要定义它们之间的适当关系。我建议你阅读the documentation on relationship fields

+0

感谢您的帮助,所有模型定义一直运行平稳。 – Chris 2010-05-19 20:02:41

相关问题