Thanks,
Geta
I know you can
specify META.db_table to specify database table names and db_column for
field names, but I couldn't see where/if this could be set for a
ManyToManyField -- is it possible?
Not yet.
There's a ticket I stumbled across yesterday that asks for this, too
(#785). I think it's not an unreasonable idea, so we should add
something like that in the near- to medium-term future.
Malcolm
In PostgreSQL you could try to:
- let Django create its m2m table
- drop it
- recreate it as a view on your original m2m table
- create an rule 'AS ON INSERT ... DO INSTEAD"
A small script which shows something like this:
/* Your original m2m table */
create table t (k int, c1 int, c2 int);
/* The view, which should copy Django's m2m table */
create view v as select k as id, c1 as t1_id, c2 as t2_id from t;
/* A rule which redirects inserts to the original m2m table */
create rule r as on insert to v
do instead
insert into t values (NEW.id, NEW.t1_id, NEW.t2_id);
/* insert some values in the view */
insert into v values (1, 1, 1);
insert into v values (2, 2, 2);
insert into v values (3, 3, 3);
/* inserts have actually gone in the original m2m table */
select * from t;
You would also need rules for updates and deletes on the view.
On MS SQLServer views are updatable to a certain extent by default, so
something similar would work there.
Of course the Django-generated m2m table and the original one have to
be pretty similar for this to work.
Cheers,
Marc