On Mon, Oct 19, 2009 at 8:03 PM, John Handelaar <j...@userfrenzy.com> wrote:

>
> Hello
>
> For reasons I won't bore you with, a Mysql legacy DB *whose schema I
> cannot alter* contains (inter alia) two tables.  I'm trying to write
> an alternative front-end to this DB in Django which would be
> read-only.
>
> tableone has a primary key called tableone_id
>
> tabletwo contains rows which have a 1:1 relationship with equivalent
> rows in tableone, and a column called tableone_id to allow me connect
> them with a JOIN.  It does not, however, have a primary key of its
> own.
>
> It seems obvious to me that these two tables belong in one Model
> definition. How do I define a single model which spans the two tables
> and returns querysets containing all columns from both tables?
>
> a)  With a model manager?  If so, where do I put that manager and are
> there any examples I can steal?
> b)  With custom SQL in the model definition?  If so, again, does
> someone have an example online I can see somewhere?
> c)  Somewhere else?
>

I think your best bet is to create a view to logically combine the tables in
the DB. You can then use the following link that I just stumbled on my self
in another thread on this list. It describes a method for accessing views
via a model.
http://wolfram.kriesing.de/blog/index.php/2007/django-nice-and-critical-article#comment-48425

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

Reply via email to