Django

Code

Changeset 2382

Show
Ignore:
Timestamp:
02/24/06 04:28:46 (3 years ago)
Author:
russellm
Message:

magic-removal: Refs #1346 -- Added the production of 'mirror' entries in the m2m table for m2m relations to self.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/fields/related.py

    r2381 r2382  
    301301                _add_m2m_items(self, superclass, rel_model, join_table, source_col_name, 
    302302                    target_col_name, instance._get_pk_val(), *objs, **kwargs) 
     303 
     304                # If this is an m2m relation to self, add the mirror entry in the m2m table 
     305                if instance.__class__ == rel_model: 
     306                    _add_m2m_items(self, superclass, rel_model, join_table, target_col_name, 
     307                        source_col_name, instance._get_pk_val(), *objs, **kwargs)                     
     308 
    303309            add.alters_data = True 
    304310 
     
    306312                _remove_m2m_items(rel_model, join_table, source_col_name, 
    307313                    target_col_name, instance._get_pk_val(), *objs) 
     314                     
     315                # If this is an m2m relation to self, remove the mirror entry in the m2m table 
     316                if instance.__class__ == rel_model: 
     317                    _remove_m2m_items(rel_model, join_table, target_col_name, 
     318                        source_col_name, instance._get_pk_val(), *objs) 
     319                     
    308320            remove.alters_data = True 
    309321 
    310322            def clear(self): 
    311323                _clear_m2m_items(join_table, source_col_name, instance._get_pk_val()) 
     324     
     325                # If this is an m2m relation to self, clear the mirror entry in the m2m table                 
     326                if instance.__class__ == rel_model: 
     327                    _clear_m2m_items(join_table, target_col_name, instance._get_pk_val()) 
     328                 
    312329            clear.alters_data = True 
    313330