Thanks for your help, Ian. Two awesome solutions; I'll try and check 'em out today if I get the chance.
Ben On Jul 15, 1:26 pm, Ian Clelland <clell...@gmail.com> wrote: > On Jul 14, 8:23 am,BenjaminKreeger <benjaminkree...@gmail.com> > wrote: > > > I was using PostgreSQL at first, but then I found information about > > reading data across databases only with MySQL, so I'm using MySQL for > > the time being. > > > Now, I don't have a database set for P1 yet because it's just > > displaying reStructuredText files; if I were to set up that site to > > access P2's database (in P1's settings.py file), would I be able to > > (eek) do raw SQL to get the data to display the way I want? Or would > > there be an easier way to do that WITHOUT raw SQL, and WITHOUT > > duplicating that model declared on P2? > > I didn't realise that P1 didn't have a database at all -- if that's > the case, then you can just use the credentials from P2 (the > DATABASE_* lines from settings.py) in P1's settings. You can define > the same models -- it's as simple as installing the same apps that P2 > uses, there should be no duplication of code, and you'll have access > to all of the P2 data from P1. > > If P1 needs its own database, however, (and you're using MySQL, and > your databases are on the same server), then you can use this patch to > django/db/backends/mysql/base.py (this is based on the 1.0.x branch; > other branches should be similar) > > =================================================================== > --- django/db/backends/mysql/base.py (revision 10742) > +++ django/db/backends/mysql/base.py (working copy) > @@ -143,7 +143,7 @@ > def quote_name(self, name): > if name.startswith("`") and name.endswith("`"): > return name # Quoting once is enough. > - return "`%s`" % name > + return ".".join(["`%s`" % name_part for name_part in > name.split(".")]) > > def random_function_sql(self): > return 'RAND()' > > That will let you define, in your P1 models, a complete table name > like this: > > class Example(models.Model): > ... fields ... > > class Meta: > db_table = 'p2_database.table_name' > > And mysql will get the data from the right database. No raw SQL > required. > > Ian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---