On Thu, May 28, 2009 at 1:11 PM, Alex Gaynor <alex.gay...@gmail.com> wrote:

>
> On Thu, May 28, 2009 at 11:51 AM, enthropyinaction <
> enthropy.in.act...@gmail.com> wrote:
>
>>
>> [snip] File "/home/django/ipdb/../ipdb/nagios/models.py", line 15, in
>> <module>
>>    class APC(models.Model):
>>  File "/home/django/ipdb/../ipdb/nagios/models.py", line 22, in APC
>>    switch = models.ForeignKey(Switches)
>> NameError: name 'Switches' is not defined
>>
>> ----------------------------------------------------------
>>
>> Basically, I'm putting together an IP address database that will
>> update our network monitor, Nagios.  I wanted to cover all my bases
>> and make it all-inclusive.  Each Switch is on a networked APC so I
>> want it foreign keyed to the APC it's on.  Each APC is networked and
>> so connected to one of the switches in the other model, so I want a
>> foreign key to the Switches model.  I need the foreign keys to set up
>> parenting in Nagios.
>>
>> I've confirmed that this is definately related to the order the models
>> are placed in because reversing the order in models.py changes the
>> name error to complain about the opposite model.  Is there any way
>> around this that I'm missing in the documentation?  I suppose I can
>> remove the foreign key and just make one of them an integer field and
>> relate it manually.  It'd just be easier to make django handle the
>> table relations.  Any suggestions?
>>
>>
>>
> Take a look at:
> http://docs.djangoproject.com/en/dev/ref/models/fields/#lazy-relationshipswhich
>  explains how to do something like this.
>

Except as described (each switch is on *a* networked APC...each APC [is]
...connected to *one* of the switches) it sounds more like the relationship
that is being described here is OneToOne (
http://docs.djangoproject.com/en/dev/topics/db/models/#one-to-one-relationships)
not a pair of ForeignKeys.

So yes, you can fix the error by using quoted names to reference models not
yet defined, but I'm not sure that the models you have defined here are
really describing the relationship you are trying to model.  You may just
need a single OneToOneField in one of the models.

Karen

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