Reread what I've written and understand it would be much better with a
sample:

class User(models.Model):
    groups = models.ManyToManyField('Group', related_name='groups',
db_table=u'USERS_TO_GROUPS')
class Group(models.Model):
    users = models.ManyToManyField(User, related_name='users',
db_table=u'USERS_TO_GROUPS')

This code works fine with existing DB and also it really helps to
generate proper form from the model. But syncdb fails since it tries
to create 2 tables with the same name.

class User(models.Model):
    groups = models.ManyToManyField('Group', related_name='groups',
db_table=u'USERS_TO_GROUPS')
class Group(models.Model):
    users = models.ManyToManyField(User, related_name='users',
db_table=u'USERS_TO_GROUPS', create_table=False)

Works fine.

Also there was some discussion in django users:
http://groups.google.com/group/django-users/browse_thread/thread/50bf564e98954a78

On Jan 22, 12:38 am, "Evgeniy Ivanov (powerfox)"
<lolkaanti...@gmail.com> wrote:
> Hi list,
> I had to implement M2M editing in both admin forms (something like
> editing userlist for group and grouplist for user). I wasn't able to
> find any fine solution, but specifying M2M in both models and creating
> tables manually (since syncdb tries to create two tables).
> I herd in the IRC, that such thing (editing in both forms) is
> abnormal, but I disagree.
> So I tried to use intermidiary model like described in the docs, but
> it is really another thing (not "pure" m2m). Another solution is
> hardcording the form, but it will require extra save code, I don't
> like it too.
>
> I think that if you add special arg (create_table) to ManyToManyField
> it can be easily implemented using models/fields/related.py:751.
>
> If you think it can go, I will create a ticket.
>
> Also there is (a kind of offtop) a very cute 
> thing:http://www.djangosnippets.org/snippets/962/
> Why isn't it in the native ManyToManyField?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to