2010-05-19 251 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

相關問題