On Fri, Jul 10, 2009 at 9:39 AM, bruno<bruno.prig...@gmail.com> wrote:
>
> 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
>
>
> [...]
>
> 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.

One solution to this is described in the relevant documentation:

http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

-- 
Ramiro Morales
http://rmorales.net

PyCon 2009 Argentina - Vie 4 y Sab 5 Septiembre
Buenos Aires, Argentina
http://ar.pycon.org/2009/about/

--~--~---------~--~----~------------~-------~--~----~
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