On Feb 12, 2008 12:51 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Tue, 2008-02-12 at 12:44 +0100, Hanne Moa wrote:
> > On Feb 12, 2008 12:16 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> > > On Tue, 2008-02-12 at 12:11 +0100, Hanne Moa wrote:
> > > > Each org only has a single region, and in the old web-interface the
> > > > region-data is shown as a drop-down-list (<select>) where you can
> > > > choose one and only one. So: org.region == region.id, there can be
> > > > many orgs in a region but only one region per org.
> > >
> > > Which means it's many-to-one, not one-to-one. If you were to draw a
> > > picture of your table rows, many rows would (potentially) be pointing to
> > > a single row in the org table. That's many-to-one.
> > >
> > > In Django a many-to-one relation is represented by a ForeignKey field.
> >
> > I'm using a ForeignKey-field for it now, but I don't see anywhere how
> > to make it behave as in the old system: in Django's admin-interface
> > for org the foreignkey is shown as a drop-down *but with nothing
> > selected*.
> >
> > When looking at the examples in the tutorial: Poll/Choice, a Poll can
> > have several Choices, but a Choice can have only a single Poll. But
> > org->region is *the other way around*. One Poll containing many
> > Choices vs. one org having one region. The fact that one region have
> > many orgs is irrelevant as region will never be editable or visible
> > anywhere else but as linked from org.
> >
> > So, how do I do that?
>
> Put the ForeignKey on the "many" side of the relation. In your case, it
> looks like it goes on the "org" model, since there are many orgs to a
> region.

I already have:

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)

class Org(models.Model):
    id = models.IntegerField(unique=True, primary_key=True)
    ..
    region = models.ForeignKey(Region, db_column = 'id') #x, Region.id
    ..
    class Admin: pass

... and in the admin-interface for Org I see Region: '----------'
instead of the expected Region: 'someregion (somelocation)'. If I add
'class Admin: pass' to Region I get to add more Regions to the Org,
which I never want. If I do the other examples in the tutorial I also
get to add more regions, which I never want.

I might have been unclear so I'll try again:
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.

> > > There are very few 'new' questions of this nature.
> >
> > Then where's the FAQ?
>
> http://www.google.com/search?q=django+FAQ

http://www.djangoproject.com/documentation/faq/

This FAQ, which I read before I came here, and which I assume is
pretty official, doesn't contain answers to my type of question. So,
is there another FAQ for such? The obvious google didn't find any.


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

Reply via email to