How to import classes into other classes within the same file in Python
- by Chris
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