On Tue, 2008-02-12 at 14:13 +0100, Hanne Moa wrote: > On Feb 12, 2008 1:56 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Tue, 2008-02-12 at 13:36 +0100, Hanne Moa wrote: > > > class Region(models.Model): > > > id = models.IntegerField(unique=True, primary_key=True) > > > region = models.CharField(maxlength=32) > > > location = models.CharField(maxlength=32) > > > class Meta: db_table = 'region' > > > > > > def __str__(self): > > > return '%s (%s)' % (self.region, self.lokasjon) > > > > Here's the problem: your __str__ method will be throwing an exception > > because the lokasion attribute doesn't exist. > > I knew you'd say that as soon as I sent it in when I noticed I hadn't > Anglified the "lokasjon"-attribute everywhere (why'd I do such a thing > in the first place? To make it easier for you, of course.) > > Now, that typo isn't there in the actual running code. I don't get any > exceptions or errors when running it. I'll repeat my question: > > 1. how do I get "Region: 'someregion (somelocation)'" in the admin > interface instead of "Region: '---------'"?
I don't know why this is happening. ForeignKeys normally just work properly. It should be working as you expect. Try using your models to create fresh database tables (against a new database, of course) to see how they should be working. When you add a region to an org, when you subsequently go back and edit the org it will show the region as selected. So there's something slightly amiss with the way things are matched up in your retrofitted models. You could also try comparing the output of "manage.py sql <app_name>" to the actual database tables to make sure the reference is pointing to the right field, etc. > 2. ...while at the same time ensuring that another Region can never be > added to that particular Org? Changed, yes, added, no. That just means not having an Admin inner class on the Region model. Regards, Malcolm -- If it walks out of your refrigerator, LET IT GO!! http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

