ManyToManyField no syncdb

1
2
3
4
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. Limit queryset to objects related to parent in ManyToMany fields within admin inlines by DrMeers 2 years, 12 months ago
  2. unique_together with many to many fields by j4nu5 1 year, 8 months ago
  3. Database file storage by powerfox 4 years, 3 months ago
  4. Display user-friendly values of a ManyToManyRawIdWidget by luc_j 2 years, 10 months ago
  5. Link raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages by EmilStenstrom 2 years, 7 months ago

Comments

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?)