I'm working on a project with multiple apps. The department app model is as follows:
from emails.models import GerenciarEmails
class Departamento(models.Model):
#modelo de grupos de disciplinas
class Meta:
verbose_name = 'Departamento'
verbose_name_plural = 'Departamentos'
titulo = models.CharField(max_length=255, verbose_name='Nome do Grupo')
watermark = models.FileField(upload_to = settings.MEDIA_ROOT+"/watermarks/", default=settings.MEDIA_ROOT+'/img/generico.gif')
cor = ColorField(blank=True)
gerencia = models.ForeignKey(GerenciarEmails)
docentes_responsaveis = models.ManyToManyField(settings.AUTH_USER_MODEL, null=True, blank=True,related_name="docentes_responsaveis_pelo_grupo", limit_choices_to={'docente':True})
def __unicode__(self):
#Modo como o Modelo e Exibido na Lista na Adminstracao
return unicode(self.titulo)
I've added the following instance to it:
gerencia = models.ForeignKey(GerenciarEmails)
ManageEmails is an email app modeling method. The import that is of interest is used, the others refer to other things.
With the insertion of this instance, Django gives the following error: ImportError: can not import name Department
Apparently it is not letting you enter this instance. Could someone help me on the reason for the error?
This is the ManageEmails method:
class GerenciarEmails(models.Model):
class Meta:
verbose_name = 'Gerenciar E-mails'
verbose_name_plural = 'Gerenciar E-mails'
departamento = models.ForeignKey(Departamento)
def __unicode__(self):
return self.departamento.titulo
As you can see, I use the Department method of models.py from the Departments app. If I put the import after this method, as is the suggestion of mgibsonbr , python gives another error:
ImportError: cannot import name Disciplina
It even makes sense, as ManageEmail needs the Department import.