On Thu, May 28, 2009 at 11:51 AM, enthropyinaction < enthropy.in.act...@gmail.com> wrote:
> > First, an excerpt from my models.py and the traceback: > > --------------------------------------------------------- > > class Loc(models.Model): > added = models.DateTimeField(auto_now_add=True) > updated = models.DateTimeField(auto_now=True) > name = models.CharField(max_length=100) > alias = models.CharField(max_length=50) > company = models.CharField('Provided by', max_length=100) > address = models.CharField(max_length=255) > phone = models.IntegerField('Contact Phone Number') > email = models.EmailField('Contact Email', max_length=75) > acct = models.CharField('Account Number(s)', max_length=255) > cid = models.CharField('Circuit ID(s)', max_length=255) > > class APC(models.Model): > added = models.DateTimeField(auto_now_add=True) > updated = models.DateTimeField(auto_now=True) > name = models.CharField(max_length=100) > domain = models.CharField(max_length=255) > ip = models.IPAddressField() > nagios = models.BooleanField() > switch = models.ForeignKey(Switches) > loc = models.ForeignKey(Loc) > snmp = models.BooleanField() > > class Switches(models.Model): > added = models.DateTimeField(auto_now_add=True) > updated = models.DateTimeField(auto_now=True) > name = models.CharField(max_length=100) > domain = models.CharField(max_length=255) > ip = models.IPAddressField() > nagios = models.BooleanField() > apc = models.ForeignKey(APC) > loc = models.ForeignKey(Loc) > snmp = models.BooleanField() > > ----------------------------------------------------- > > Traceback (most recent call last): > File "manage.py", line 11, in <module> > execute_manager(settings) > File "/usr/lib/python2.5/site-packages/django/core/management/ > __init__.py", line 340, in execute_manager > utility.execute() > File "/usr/lib/python2.5/site-packages/django/core/management/ > __init__.py", line 295, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 77, in run_from_argv > self.execute(*args, **options.__dict__) > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 95, in execute > self.validate() > File "/usr/lib/python2.5/site-packages/django/core/management/ > base.py", line 122, in validate > num_errors = get_validation_errors(s, app) > File "/usr/lib/python2.5/site-packages/django/core/management/ > validation.py", line 28, in get_validation_errors > for (app_name, error) in get_app_errors().items(): > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 128, in get_app_errors > self._populate() > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 57, in _populate > self.load_app(app_name, True) > File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", > line 72, in load_app > mod = __import__(app_name, {}, {}, ['models']) > 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. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---