On Tue, 2008-02-12 at 12:11 +0100, Hanne Moa wrote:
> Just starting out with Django here...
> 
> In an existing database whose existing table-structure must remain
> unchanged by django, I have several cases of what looks like a
> OneToOne, for instance:
> 
> The table/class org has a field region which points to the id on the
> table/class region (dump from postgres):
> 
> CREATE TABLE org (
>   ..
>   region integer,
>   ..
> );
> 
> CREATE TABLE region (
>   id integer NOT NULL,
>   region character varying(32) NOT NULL,    -- county, state
>   location character varying(32) NOT NULL  -- location within region
> );
> 
> ALTER TABLE ONLY org
>   ADD CONSTRAINT "$5" FOREIGN KEY (region) REFERENCES region(id);
> 
> 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.

[...]
> (Oh, and having a way to make a model inherit from another (single
> inheritance is fine) would be swell. The obvious way didn't work.)

Two minutes searching for "model inheritance" in the archives reveals
that it is work in progress.

If you're just starting out, you're going to want to spend a bit of time
searching in the django-users archives (or just searching in Google and
making sure "django" is in the query). There are very few 'new'
questions of this nature.

Regards,
Malcolm

-- 
If you think nobody cares, try missing a couple of payments. 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to