Ticket #11226: m2m_name_clashes.diff

File m2m_name_clashes.diff, 1.4 KB (added by pkoch, 6 years ago)

Sugested solution

  • django/db/models/fields/related.py

     
    816816                        self._m2m_column_name_cache = f.column
    817817                        break
    818818            # If this is an m2m relation to self, avoid the inevitable name clash
    819             elif related.model == related.parent_model:
     819            elif related.model._meta.object_name == related.parent_model._meta.object_name:
    820820                self._m2m_column_name_cache = 'from_' + related.model._meta.object_name.lower() + '_id'
    821821            else:
    822822                self._m2m_column_name_cache = related.model._meta.object_name.lower() + '_id'
     
    847847                            self._m2m_reverse_name_cache = f.column
    848848                            break
    849849            # If this is an m2m relation to self, avoid the inevitable name clash
    850             elif related.model == related.parent_model:
     850            elif related.model._meta.object_name == related.parent_model._meta.object_name:
    851851                self._m2m_reverse_name_cache = 'to_' + related.parent_model._meta.object_name.lower() + '_id'
    852852            else:
    853853                self._m2m_reverse_name_cache = related.parent_model._meta.object_name.lower() + '_id'
Back to Top