views:

76

answers:

2

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_length=30)
    files = models.ManyToManyField(ProjectFile)

    def __unicode__(self):
            return self.typeOf
A: 

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

mcpeterson
Thanks for the tip.
Chris
+3  A: 

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.

Daniel Roseman
Thanks for the help, all is running smoothly now as far as the model definitions go.
Chris