Hi,

I'm new in django and I have problem with importing models

I have two class : Job and Event

The Job class defines a method run_job() wich do something and log the
result by creating a new Event so I need to import the Event class
from file app/events/models.py
The Event class reference the job who created the log entry so I need
to import the Job class from file app/jobs/models.py


file : app/jobs/models.py
--------------------------------------

from events.models import Event
...

class Job(models.Model):
...
    def run_job(self):
        result = do_something()
        e = Event(timestamp_gmt=datetime.now(), job=self,
result=result)
        self.save()
        return result


file : app/events/models.py
------------------------------------------

from jobs.models import Job
...

class Event(models.Model):
...
    timestamp_gmt = models.DateTimeField(null=False, editable=False)
    job = models.ForeignKey(Job, blank=False, null=False)


When I start the serveur I have the following error :
...
  File "app\jobs\models.py", line 8, in <module>
    from events.models import Event
  File "app\events\models.py", line 12, in <module>
    class Event(models.Model):
  File "app\events\models.py", line 14, in Event
    job = models.ForeignKey(Job, blank=False, null=False)
NameError: name 'Job' is not defined

It's like Django doesn't like the cross import between Job and Event.
Anyone can tell me what I'm doing wrong ?
I think the easy solution is to declar the Event class in the Job
model file but I'd like to keep them in different files.

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to