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: '---------'"? 2. ...while at the same time ensuring that another Region can never be added to that particular Org? Changed, yes, added, no. By subclassing ForeignKey or is there a parameter/flag/option to set somewhere? > > class Org(models.Model): > > id = models.IntegerField(unique=True, primary_key=True) > > .. > > region = models.ForeignKey(Region, db_column = 'id') #x, Region.id > > By default, ForeignKeys refer to the primary key of the related model. > So you can do away with the db_column attribute here if you want to be > more succient. Good to know. > > http://www.djangoproject.com/documentation/faq/ > > > > This FAQ doesn't contain answers to my type of question. > > a lot of questions of already been asked previously > on this very mailing list. So I am suggesting that you do the natural > things and search the mailing list archives (or just use Google and > don't even restrict it to the django-user archives). View the mailing > list as an ever-growing, live list of frequently asked questions (and > multiple answers). I'll take this as a suggestion to make a FAQ for these types of questions as I detest having to only depend on search through a mailinglist/wiki/bbs/irclog/whatever, then finding an answer from last century with a solution that no longer works. Or a solution written in a language I don't read. Or a solution to the wrong problem, or... I'll even strive to make this FAQ a proper Django app, now there's a win-win for us all. HM --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

