开发者

How to import classes into other classes within the same file in Python

I have the file below and it is part of a django project called projectmanager, this file is projectmanager/projects/models.py . Whenever I use the python interpreter to import a Project just to test the functionality i get a name error for line 8 that FileRepo() cannot be found. How Can I import these classes correctly? Ideally what I am looking for is each Project to contain multiple FileRepos which each contain and unknown number of files. Thanks for any assistance in advance.

#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_l开发者_如何学Goength=30)
    files = models.ManyToManyField(ProjectFile)

    def __unicode__(self):
            return self.typeOf


Although McPeterson is right in general that for a name to be found, it has to be defined above where it is used, in your case that won't help. In Django, you can't arbitrarily assign classes to be properties of other classes. You need to define proper relationships between them. I suggest you read the documentation on relationship fields.


Have you declared FileRepo before you call it? IE, moving class FileRepo ahead of class Project in the models.py file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜