I'm using this little jewel of a Django code snippet to edit a ManyToManyField from both directions:
class ManyToManyField_NoSyncdb(models.ManyToManyField):
def __init__(self, *args, **kwargs):
super(ManyToManyField_NoSyncdb, self).__init__(*args, **kwargs)
self.creates_table = False
class Job(models.Model):
persons = ManyToManyField_NoSyncdb( Person, blank=True, db_table='person_jobs' )
(snippet details here)
It lets me select all the persons in a given job from the jobs form and inversely lets me select all the jobs for a person from the persons form and updates the single jobs_persons table in both cases.
Upon moving from Django 1.0 to 1.2, however, syncdb now generates a duplicate table error because creates_table is evidently no longer a supported property in the base class.
Is there another way to instruct Django 1.2 not to create a table for a RelatedField?
So, if you want to have access to the ManyToMany in both models in the Admin, currently the official solution is to use inlinemodel for the second model. I had also this same problem/need just a few days ago. And I was not really satisfied with the inlinemodel solution (heavy in DB queries if you have a lot of entries, cannot use the
filter_horizontal
widget, etc.).The solution I found (that's working with Django 1.2+ and
syncdb
) is this:See ticket 897 for more info.
Unfortunately, if you're using South you will have to remove the creation of the
app_user_group
table in every migration file created automatically.