ManyToManyField no syncdb

class ManyToManyField_NoSyncdb(models.ManyToManyField):
    def __init__(self, *args, **kwargs):
        super(ManyToManyField_NoSyncdb, self).__init__(*args, **kwargs)
        self.creates_table = False

More like this

  1. FieldAccessForm (per-field user access for forms derived from models) by Killarny 5 years, 6 months ago
  2. ModelForm Class saving m2m by ckarrie2 2 years, 6 months ago
  3. DefaultValueWidget by miracle2k 6 years, 9 months ago
  4. Link raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages by EmilStenstrom 3 years, 6 months ago
  5. Manager for something like __inall by apollo13 6 years, 5 months ago


dkg (on February 3, 2010):

Thanks, this was very useful to me, because i have m2m relationships that i want to look at from both directions.

In fact, it seems useful enough that it might be handy to have a creates_table argument to the built-in ManyToManyField (defaults to True), so this workaround wouldn't be necessary.


volman_jeff (on February 2, 2011):

Warning! This snippet fails in Django 1.2.3 since the Field property "creates_table" appears to no longer be supported. It tries to create the table which generates a "duplicate table" error.


(Forgotten your password?)