It's completely logical. You've specified two separate relations here,
not the same relation from both ends.
[...]
> How can I add m2m to both models without using third model with
> foreign keys (or with it, but without extra ID field)? If to be
> sincere it doesn't make much sense, but everything in Django should be
> perfect :)
You only specify the field on one model and it's available at both ends.
This is a design feature so that you *don't* have to write the same
thing twice. So the answer to your question is to specify the ManyToMany
field on one model.
So the solution to your problem is "don't do that". "Perfect" doesn't
mean you can use whatever syntax you like. In Django, each time you
write ManyToManyField, you are specify a new relation between two
models.
You need to go back and look at your original problem. You wanted forms
with multiselect fields for both forms. So the real question is "how do
you do that". I suspect the answer is that you have to manually
construct one of the forms (which you can write a helper function to do
if you need this in a lot of projects, or, if this only happens for one
model, just write a single form class). The other answer is to rethink
your data entry so that this kind of bi-directional multi-select isn't
necessary. It's not a really common UI pattern and you can probably
think of ways to avoid it.
Regards,
Malcolm
[...]
> > You need to go back and look at your original problem. You wanted forms
> > with multiselect fields for both forms. So the real question is "how do
> > you do that". I suspect the answer is that you have to manually
> > construct one of the forms (which you can write a helper function to do
> > if you need this in a lot of projects, or, if this only happens for one
> > model, just write a single form class).
>
> Thanks, will try. Current sollution (create table manually and specify
> name/columns) is neither right or cute.
I think part of the conceptual problem here is that you're trying to
solve your problem by working on the model definition. But the problem
is a form issue. It's about presentation, not data storage. So approach
it from that end.
Regards,
Malcolm
How is it wrong that when you want a custom form you have to actually
write some code? Django cannot read your mind. It cannot possibly
accommodate every single use-case of every person on the planet out of
the box. It's designed to be extensible for precisely that reason.
"I have to write some code" is not a bad thing. Django is a library for
programmers.
> I think it would be much better to specify both M2M fields with the
> same table name.
Well, have lots of fun implementing your own field type to do this, if
it's what you want.
Django's ManyToManyField is, and always will be, specified on exactly on
model. That describes the data and the programmatic API. Trying to hack
that to modify the presentation of a form is still attacking the wrong
end of the problem.
Malcolm