<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . db . migrations . operations . base import Operation <EOL> from django . db . migrations . state import ModelState <EOL> from django . db . models . options import normalize_together <EOL> from django . utils import six <EOL> from django . utils . functional import cached_property <EOL> from . fields import ( <EOL> AddField , AlterField , FieldOperation , RemoveField , RenameField , <EOL> ) <EOL> def _check_for_duplicates ( arg_name , objs ) : <EOL> used_vals = set ( ) <EOL> for val in objs : <EOL> if val in used_vals : <EOL> raise ValueError ( <EOL> "<STR_LIT>" % ( val , arg_name ) <EOL> ) <EOL> used_vals . add ( val ) <EOL> class ModelOperation ( Operation ) : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> @ cached_property <EOL> def name_lower ( self ) : <EOL> return self . name . lower ( ) <EOL> def references_model ( self , name , app_label = None ) : <EOL> return name . lower ( ) == self . name_lower <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> return ( <EOL> super ( ModelOperation , self ) . reduce ( operation , in_between , app_label = app_label ) or <EOL> not operation . references_model ( self . name , app_label ) <EOL> ) <EOL> class CreateModel ( ModelOperation ) : <EOL> """<STR_LIT>""" <EOL> serialization_expand_args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , name , fields , options = None , bases = None , managers = None ) : <EOL> self . fields = fields <EOL> self . options = options or { } <EOL> self . bases = bases or ( models . Model , ) <EOL> self . managers = managers or [ ] <EOL> super ( CreateModel , self ) . __init__ ( name ) <EOL> _check_for_duplicates ( '<STR_LIT>' , ( name for name , _ in self . fields ) ) <EOL> _check_for_duplicates ( '<STR_LIT>' , ( <EOL> base . _meta . label_lower if hasattr ( base , '<STR_LIT>' ) else <EOL> base . lower ( ) if isinstance ( base , six . string_types ) else base <EOL> for base in self . bases <EOL> ) ) <EOL> _check_for_duplicates ( '<STR_LIT>' , ( name for name , _ in self . managers ) ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . fields , <EOL> } <EOL> if self . options : <EOL> kwargs [ '<STR_LIT>' ] = self . options <EOL> if self . bases and self . bases != ( models . Model , ) : <EOL> kwargs [ '<STR_LIT>' ] = self . bases <EOL> if self . managers and self . managers != [ ( '<STR_LIT>' , models . Manager ( ) ) ] : <EOL> kwargs [ '<STR_LIT>' ] = self . managers <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> state . add_model ( ModelState ( <EOL> app_label , <EOL> self . name , <EOL> list ( self . fields ) , <EOL> dict ( self . options ) , <EOL> tuple ( self . bases ) , <EOL> list ( self . managers ) , <EOL> ) ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , model ) : <EOL> schema_editor . create_model ( model ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> model = from_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , model ) : <EOL> schema_editor . delete_model ( model ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( "<STR_LIT>" if self . options . get ( "<STR_LIT>" , False ) else "<STR_LIT>" , self . name ) <EOL> def references_model ( self , name , app_label = None ) : <EOL> strings_to_check = [ self . name ] <EOL> for base in self . bases : <EOL> if isinstance ( base , six . string_types ) : <EOL> strings_to_check . append ( base . split ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> for fname , field in self . fields : <EOL> if field . remote_field : <EOL> if isinstance ( field . remote_field . model , six . string_types ) : <EOL> strings_to_check . append ( field . remote_field . model . split ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> for string in strings_to_check : <EOL> if string . lower ( ) == name . lower ( ) : <EOL> return True <EOL> return False <EOL> def model_to_key ( self , model ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( model , six . string_types ) : <EOL> return model . split ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> else : <EOL> return model . _meta . app_label , model . _meta . object_name <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> if ( isinstance ( operation , DeleteModel ) and <EOL> self . name_lower == operation . name_lower and <EOL> not self . options . get ( "<STR_LIT>" , False ) ) : <EOL> return [ ] <EOL> elif isinstance ( operation , RenameModel ) and self . name_lower == operation . old_name_lower : <EOL> return [ <EOL> CreateModel ( <EOL> operation . new_name , <EOL> fields = self . fields , <EOL> options = self . options , <EOL> bases = self . bases , <EOL> managers = self . managers , <EOL> ) , <EOL> ] <EOL> elif isinstance ( operation , FieldOperation ) and self . name_lower == operation . model_name_lower : <EOL> if isinstance ( operation , AddField ) : <EOL> if hasattr ( operation . field , "<STR_LIT>" ) and operation . field . remote_field : <EOL> for between in in_between : <EOL> app_label , object_name = self . model_to_key ( operation . field . remote_field . model ) <EOL> if between . references_model ( object_name , app_label ) : <EOL> return False <EOL> if getattr ( operation . field . remote_field , "<STR_LIT>" , None ) : <EOL> app_label , object_name = self . model_to_key ( operation . field . remote_field . through ) <EOL> if between . references_model ( object_name , app_label ) : <EOL> return False <EOL> return [ <EOL> CreateModel ( <EOL> self . name , <EOL> fields = self . fields + [ ( operation . name , operation . field ) ] , <EOL> options = self . options , <EOL> bases = self . bases , <EOL> managers = self . managers , <EOL> ) , <EOL> ] <EOL> elif isinstance ( operation , AlterField ) : <EOL> return [ <EOL> CreateModel ( <EOL> self . name , <EOL> fields = [ <EOL> ( n , operation . field if n == operation . name else v ) <EOL> for n , v in self . fields <EOL> ] , <EOL> options = self . options , <EOL> bases = self . bases , <EOL> managers = self . managers , <EOL> ) , <EOL> ] <EOL> elif isinstance ( operation , RemoveField ) : <EOL> return [ <EOL> CreateModel ( <EOL> self . name , <EOL> fields = [ <EOL> ( n , v ) <EOL> for n , v in self . fields <EOL> if n . lower ( ) != operation . name_lower <EOL> ] , <EOL> options = self . options , <EOL> bases = self . bases , <EOL> managers = self . managers , <EOL> ) , <EOL> ] <EOL> elif isinstance ( operation , RenameField ) : <EOL> return [ <EOL> CreateModel ( <EOL> self . name , <EOL> fields = [ <EOL> ( operation . new_name if n == operation . old_name else n , v ) <EOL> for n , v in self . fields <EOL> ] , <EOL> options = self . options , <EOL> bases = self . bases , <EOL> managers = self . managers , <EOL> ) , <EOL> ] <EOL> return super ( CreateModel , self ) . reduce ( operation , in_between , app_label = app_label ) <EOL> class DeleteModel ( ModelOperation ) : <EOL> """<STR_LIT>""" <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> state . remove_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> model = from_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , model ) : <EOL> schema_editor . delete_model ( model ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , model ) : <EOL> schema_editor . create_model ( model ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . name , ) <EOL> class RenameModel ( ModelOperation ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , old_name , new_name ) : <EOL> self . old_name = old_name <EOL> self . new_name = new_name <EOL> super ( RenameModel , self ) . __init__ ( old_name ) <EOL> @ cached_property <EOL> def old_name_lower ( self ) : <EOL> return self . old_name . lower ( ) <EOL> @ cached_property <EOL> def new_name_lower ( self ) : <EOL> return self . new_name . lower ( ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT>' : self . old_name , <EOL> '<STR_LIT>' : self . new_name , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> apps = state . apps <EOL> model = apps . get_model ( app_label , self . old_name ) <EOL> model . _meta . apps = apps <EOL> all_related_objects = ( <EOL> f for f in model . _meta . get_fields ( include_hidden = True ) <EOL> if f . auto_created and not f . concrete and ( not f . hidden or f . many_to_many ) <EOL> ) <EOL> state . models [ app_label , self . new_name_lower ] = state . models [ app_label , self . old_name_lower ] <EOL> state . models [ app_label , self . new_name_lower ] . name = self . new_name <EOL> state . remove_model ( app_label , self . old_name_lower ) <EOL> for related_object in all_related_objects : <EOL> if related_object . model is not model : <EOL> continue <EOL> if related_object . related_model == model : <EOL> related_key = ( app_label , self . new_name_lower ) <EOL> else : <EOL> related_key = ( <EOL> related_object . related_model . _meta . app_label , <EOL> related_object . related_model . _meta . model_name , <EOL> ) <EOL> new_fields = [ ] <EOL> for name , field in state . models [ related_key ] . fields : <EOL> if name == related_object . field . name : <EOL> field = field . clone ( ) <EOL> field . remote_field . model = "<STR_LIT>" % ( app_label , self . new_name ) <EOL> new_fields . append ( ( name , field ) ) <EOL> state . models [ related_key ] . fields = new_fields <EOL> state . reload_model ( * related_key ) <EOL> state . reload_model ( app_label , self . new_name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> new_model = to_state . apps . get_model ( app_label , self . new_name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , new_model ) : <EOL> old_model = from_state . apps . get_model ( app_label , self . old_name ) <EOL> schema_editor . alter_db_table ( <EOL> new_model , <EOL> old_model . _meta . db_table , <EOL> new_model . _meta . db_table , <EOL> ) <EOL> for related_object in old_model . _meta . related_objects : <EOL> if related_object . related_model == old_model : <EOL> model = new_model <EOL> related_key = ( app_label , self . new_name_lower ) <EOL> else : <EOL> model = related_object . related_model <EOL> related_key = ( <EOL> related_object . related_model . _meta . app_label , <EOL> related_object . related_model . _meta . model_name , <EOL> ) <EOL> to_field = to_state . apps . get_model ( <EOL> * related_key <EOL> ) . _meta . get_field ( related_object . field . name ) <EOL> schema_editor . alter_field ( <EOL> model , <EOL> related_object . field , <EOL> to_field , <EOL> ) <EOL> fields = zip ( old_model . _meta . local_many_to_many , new_model . _meta . local_many_to_many ) <EOL> for ( old_field , new_field ) in fields : <EOL> if new_field . model == new_field . related_model or not new_field . remote_field . through . _meta . auto_created : <EOL> continue <EOL> old_m2m_model = old_field . remote_field . through <EOL> new_m2m_model = new_field . remote_field . through <EOL> schema_editor . alter_db_table ( <EOL> new_m2m_model , <EOL> old_m2m_model . _meta . db_table , <EOL> new_m2m_model . _meta . db_table , <EOL> ) <EOL> schema_editor . alter_field ( <EOL> new_m2m_model , <EOL> old_m2m_model . _meta . get_field ( old_model . _meta . model_name ) , <EOL> new_m2m_model . _meta . get_field ( new_model . _meta . model_name ) , <EOL> ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> self . new_name_lower , self . old_name_lower = self . old_name_lower , self . new_name_lower <EOL> self . new_name , self . old_name = self . old_name , self . new_name <EOL> self . database_forwards ( app_label , schema_editor , from_state , to_state ) <EOL> self . new_name_lower , self . old_name_lower = self . old_name_lower , self . new_name_lower <EOL> self . new_name , self . old_name = self . old_name , self . new_name <EOL> def references_model ( self , name , app_label = None ) : <EOL> return ( <EOL> name . lower ( ) == self . old_name_lower or <EOL> name . lower ( ) == self . new_name_lower <EOL> ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . old_name , self . new_name ) <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> if ( isinstance ( operation , RenameModel ) and <EOL> self . new_name_lower == operation . old_name_lower ) : <EOL> return [ <EOL> RenameModel ( <EOL> self . old_name , <EOL> operation . new_name , <EOL> ) , <EOL> ] <EOL> return ( <EOL> super ( ModelOperation , self ) . reduce ( operation , in_between , app_label = app_label ) or <EOL> not operation . references_model ( self . new_name , app_label ) <EOL> ) <EOL> class AlterModelTable ( ModelOperation ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , table ) : <EOL> self . table = table <EOL> super ( AlterModelTable , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . table , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> state . models [ app_label , self . name_lower ] . options [ "<STR_LIT>" ] = self . table <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> new_model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , new_model ) : <EOL> old_model = from_state . apps . get_model ( app_label , self . name ) <EOL> schema_editor . alter_db_table ( <EOL> new_model , <EOL> old_model . _meta . db_table , <EOL> new_model . _meta . db_table , <EOL> ) <EOL> for ( old_field , new_field ) in zip ( old_model . _meta . local_many_to_many , new_model . _meta . local_many_to_many ) : <EOL> if new_field . remote_field . through . _meta . auto_created : <EOL> schema_editor . alter_db_table ( <EOL> new_field . remote_field . through , <EOL> old_field . remote_field . through . _meta . db_table , <EOL> new_field . remote_field . through . _meta . db_table , <EOL> ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> return self . database_forwards ( app_label , schema_editor , from_state , to_state ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . name , self . table ) <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> if isinstance ( operation , ( AlterModelTable , DeleteModel ) ) and self . name_lower == operation . name_lower : <EOL> return [ operation ] <EOL> return super ( AlterModelTable , self ) . reduce ( operation , in_between , app_label = app_label ) <EOL> class ModelOptionOperation ( ModelOperation ) : <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> if isinstance ( operation , ( self . __class__ , DeleteModel ) ) and self . name_lower == operation . name_lower : <EOL> return [ operation ] <EOL> return super ( ModelOptionOperation , self ) . reduce ( operation , in_between , app_label = app_label ) <EOL> class FieldRelatedOptionOperation ( ModelOptionOperation ) : <EOL> def reduce ( self , operation , in_between , app_label = None ) : <EOL> if ( isinstance ( operation , FieldOperation ) and <EOL> self . name_lower == operation . model_name_lower and <EOL> not self . references_field ( operation . model_name , operation . name ) ) : <EOL> return [ operation , self ] <EOL> return super ( FieldRelatedOptionOperation , self ) . reduce ( operation , in_between , app_label = app_label ) <EOL> class AlterUniqueTogether ( FieldRelatedOptionOperation ) : <EOL> """<STR_LIT>""" <EOL> option_name = "<STR_LIT>" <EOL> def __init__ ( self , name , unique_together ) : <EOL> unique_together = normalize_together ( unique_together ) <EOL> self . unique_together = set ( tuple ( cons ) for cons in unique_together ) <EOL> super ( AlterUniqueTogether , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . unique_together , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> model_state = state . models [ app_label , self . name_lower ] <EOL> model_state . options [ self . option_name ] = self . unique_together <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> new_model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , new_model ) : <EOL> old_model = from_state . apps . get_model ( app_label , self . name ) <EOL> schema_editor . alter_unique_together ( <EOL> new_model , <EOL> getattr ( old_model . _meta , self . option_name , set ( ) ) , <EOL> getattr ( new_model . _meta , self . option_name , set ( ) ) , <EOL> ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> return self . database_forwards ( app_label , schema_editor , from_state , to_state ) <EOL> def references_field ( self , model_name , name , app_label = None ) : <EOL> return ( <EOL> self . references_model ( model_name , app_label ) and <EOL> ( <EOL> not self . unique_together or <EOL> any ( ( name in together ) for together in self . unique_together ) <EOL> ) <EOL> ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . option_name , self . name , len ( self . unique_together or '<STR_LIT>' ) ) <EOL> class AlterIndexTogether ( FieldRelatedOptionOperation ) : <EOL> """<STR_LIT>""" <EOL> option_name = "<STR_LIT>" <EOL> def __init__ ( self , name , index_together ) : <EOL> index_together = normalize_together ( index_together ) <EOL> self . index_together = set ( tuple ( cons ) for cons in index_together ) <EOL> super ( AlterIndexTogether , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . index_together , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> model_state = state . models [ app_label , self . name_lower ] <EOL> model_state . options [ self . option_name ] = self . index_together <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> new_model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , new_model ) : <EOL> old_model = from_state . apps . get_model ( app_label , self . name ) <EOL> schema_editor . alter_index_together ( <EOL> new_model , <EOL> getattr ( old_model . _meta , self . option_name , set ( ) ) , <EOL> getattr ( new_model . _meta , self . option_name , set ( ) ) , <EOL> ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> return self . database_forwards ( app_label , schema_editor , from_state , to_state ) <EOL> def references_field ( self , model_name , name , app_label = None ) : <EOL> return ( <EOL> self . references_model ( model_name , app_label ) and <EOL> ( <EOL> not self . index_together or <EOL> any ( ( name in together ) for together in self . index_together ) <EOL> ) <EOL> ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . option_name , self . name , len ( self . index_together or '<STR_LIT>' ) ) <EOL> class AlterOrderWithRespectTo ( FieldRelatedOptionOperation ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , order_with_respect_to ) : <EOL> self . order_with_respect_to = order_with_respect_to <EOL> super ( AlterOrderWithRespectTo , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . order_with_respect_to , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> model_state = state . models [ app_label , self . name_lower ] <EOL> model_state . options [ '<STR_LIT>' ] = self . order_with_respect_to <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> to_model = to_state . apps . get_model ( app_label , self . name ) <EOL> if self . allow_migrate_model ( schema_editor . connection . alias , to_model ) : <EOL> from_model = from_state . apps . get_model ( app_label , self . name ) <EOL> if from_model . _meta . order_with_respect_to and not to_model . _meta . order_with_respect_to : <EOL> schema_editor . remove_field ( from_model , from_model . _meta . get_field ( "<STR_LIT>" ) ) <EOL> elif to_model . _meta . order_with_respect_to and not from_model . _meta . order_with_respect_to : <EOL> field = to_model . _meta . get_field ( "<STR_LIT>" ) <EOL> if not field . has_default ( ) : <EOL> field . default = <NUM_LIT:0> <EOL> schema_editor . add_field ( <EOL> from_model , <EOL> field , <EOL> ) <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> self . database_forwards ( app_label , schema_editor , from_state , to_state ) <EOL> def references_field ( self , model_name , name , app_label = None ) : <EOL> return ( <EOL> self . references_model ( model_name , app_label ) and <EOL> ( <EOL> self . order_with_respect_to is None or <EOL> name == self . order_with_respect_to <EOL> ) <EOL> ) <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . name , self . order_with_respect_to ) <EOL> class AlterModelOptions ( ModelOptionOperation ) : <EOL> """<STR_LIT>""" <EOL> ALTER_OPTION_KEYS = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def __init__ ( self , name , options ) : <EOL> self . options = options <EOL> super ( AlterModelOptions , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> kwargs = { <EOL> '<STR_LIT:name>' : self . name , <EOL> '<STR_LIT>' : self . options , <EOL> } <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ ] , <EOL> kwargs <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> model_state = state . models [ app_label , self . name_lower ] <EOL> model_state . options = dict ( model_state . options ) <EOL> model_state . options . update ( self . options ) <EOL> for key in self . ALTER_OPTION_KEYS : <EOL> if key not in self . options and key in model_state . options : <EOL> del model_state . options [ key ] <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> pass <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> pass <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . name , ) <EOL> class AlterModelManagers ( ModelOptionOperation ) : <EOL> """<STR_LIT>""" <EOL> serialization_expand_args = [ '<STR_LIT>' ] <EOL> def __init__ ( self , name , managers ) : <EOL> self . managers = managers <EOL> super ( AlterModelManagers , self ) . __init__ ( name ) <EOL> def deconstruct ( self ) : <EOL> return ( <EOL> self . __class__ . __name__ , <EOL> [ self . name , self . managers ] , <EOL> { } <EOL> ) <EOL> def state_forwards ( self , app_label , state ) : <EOL> model_state = state . models [ app_label , self . name_lower ] <EOL> model_state . managers = list ( self . managers ) <EOL> state . reload_model ( app_label , self . name_lower ) <EOL> def database_forwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> pass <EOL> def database_backwards ( self , app_label , schema_editor , from_state , to_state ) : <EOL> pass <EOL> def describe ( self ) : <EOL> return "<STR_LIT>" % ( self . name , ) </s>
