Ticket #3390: serializer.diff
File serializer.diff, 9.0 KB (added by , 18 years ago) |
---|
-
django/db/backends/ado_mssql/base.py
125 125 def get_random_function_sql(): 126 126 return "RAND()" 127 127 128 def get_deferrable_sql(): 129 return " DEFERRABLE INITIALLY DEFERRED" 130 128 131 def get_fulltext_search_sql(field_name): 129 132 raise NotImplementedError 130 133 -
django/db/backends/postgresql/base.py
136 136 def get_random_function_sql(): 137 137 return "RANDOM()" 138 138 139 def get_deferrable_sql(): 140 return " DEFERRABLE INITIALLY DEFERRED" 141 139 142 def get_fulltext_search_sql(field_name): 140 143 raise NotImplementedError 141 144 -
django/db/backends/sqlite3/base.py
139 139 def get_random_function_sql(): 140 140 return "RANDOM()" 141 141 142 def get_deferrable_sql(): 143 return "" 144 142 145 def get_fulltext_search_sql(field_name): 143 146 raise NotImplementedError 144 147 -
django/db/backends/mysql/base.py
174 174 def get_random_function_sql(): 175 175 return "RAND()" 176 176 177 def get_deferrable_sql(): 178 return "" 179 177 180 def get_fulltext_search_sql(field_name): 178 181 return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name 179 182 -
django/db/backends/oracle/base.py
108 108 def get_random_function_sql(): 109 109 return "DBMS_RANDOM.RANDOM" 110 110 111 def get_deferrable_sql(): 112 return " DEFERRABLE INITIALLY DEFERRED" 113 111 114 def get_fulltext_search_sql(field_name): 112 115 raise NotImplementedError 113 116 -
django/db/backends/postgresql_psycopg2/base.py
96 96 def get_random_function_sql(): 97 97 return "RANDOM()" 98 98 99 def get_deferrable_sql(): 100 return " DEFERRABLE INITIALLY DEFERRED" 101 99 102 def get_fulltext_search_sql(field_name): 100 103 raise NotImplementedError 101 104 -
django/db/backends/dummy/base.py
36 36 get_date_trunc_sql = complain 37 37 get_limit_offset_sql = complain 38 38 get_random_function_sql = complain 39 get_deferrable_sql = complain 39 40 get_fulltext_search_sql = complain 40 41 get_drop_foreignkey_sql = complain 41 42 OPERATOR_MAPPING = {} -
django/core/serializers/python.py
72 72 pks = [] 73 73 for pk in field_value: 74 74 if isinstance(pk, unicode): 75 pk = pk.encode(options.get("encoding", settings.DEFAULT_CHARSET)) 76 m2m_data[field.name] = field.rel.to._default_manager.in_bulk(field_value).values() 75 pks.append(pk.encode(options.get("encoding", settings.DEFAULT_CHARSET))) 76 else: 77 pks.append(pk) 78 m2m_data[field.name] = pks 77 79 78 80 # Handle FK fields 79 elif field.rel and isinstance(field.rel, models.ManyToOneRel) and field_value is not None: 80 try: 81 data[field.name] = field.rel.to._default_manager.get(pk=field_value) 82 except field.rel.to.DoesNotExist: 83 data[field.name] = None 81 elif field.rel and isinstance(field.rel, models.ManyToOneRel): 82 data[field.attname] = field_value 84 83 85 84 # Handle all other fields 86 85 else: -
django/core/management.py
167 167 if f.rel.to in known_models: 168 168 field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \ 169 169 style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \ 170 style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' 170 style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' + 171 backend.get_deferrable_sql() 171 172 ) 172 173 else: 173 174 # We haven't yet created the table to which this field … … 210 211 # For MySQL, r_name must be unique in the first 64 characters. 211 212 # So we are careful with character usage here. 212 213 r_name = '%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table)))) 213 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) ;' % \214 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ 214 215 (backend.quote_name(r_table), r_name, 215 backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col))) 216 backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col), 217 backend.get_deferrable_sql())) 216 218 del pending_references[model] 217 219 return final_output 218 220 … … 232 234 (style.SQL_FIELD(backend.quote_name('id')), 233 235 style.SQL_COLTYPE(data_types['AutoField']), 234 236 style.SQL_KEYWORD('NOT NULL PRIMARY KEY'))) 235 table_output.append(' %s %s %s %s (%s) ,' % \237 table_output.append(' %s %s %s %s (%s)%s,' % \ 236 238 (style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), 237 239 style.SQL_COLTYPE(data_types[get_rel_data_type(opts.pk)] % opts.pk.__dict__), 238 240 style.SQL_KEYWORD('NOT NULL REFERENCES'), 239 241 style.SQL_TABLE(backend.quote_name(opts.db_table)), 240 style.SQL_FIELD(backend.quote_name(opts.pk.column)))) 241 table_output.append(' %s %s %s %s (%s),' % \ 242 style.SQL_FIELD(backend.quote_name(opts.pk.column)), 243 backend.get_deferrable_sql())) 244 table_output.append(' %s %s %s %s (%s)%s,' % \ 242 245 (style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())), 243 246 style.SQL_COLTYPE(data_types[get_rel_data_type(f.rel.to._meta.pk)] % f.rel.to._meta.pk.__dict__), 244 247 style.SQL_KEYWORD('NOT NULL REFERENCES'), 245 248 style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)), 246 style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)))) 249 style.SQL_FIELD(backend.quote_name(f.rel.to._meta.pk.column)), 250 backend.get_deferrable_sql())) 247 251 table_output.append(' %s (%s, %s)' % \ 248 252 (style.SQL_KEYWORD('UNIQUE'), 249 253 style.SQL_FIELD(backend.quote_name(f.m2m_column_name())), -
tests/modeltests/serializers/models.py
139 139 ... print obj 140 140 <DeserializedObject: Profile of Joe> 141 141 142 # Objects ids can be referenced before they are defined in the serialization data 143 # However, the deserialization process will need to be contained within a transaction 144 >>> json = '[{"pk": "3", "model": "serializers.article", "fields": {"headline": "Forward references pose no problem", "pub_date": "2006-06-16 15:00:00", "categories": [4, 1], "author": 4}}, {"pk": "4", "model": "serializers.category", "fields": {"name": "Reference"}}, {"pk": "4", "model": "serializers.author", "fields": {"name": "Agnes"}}]' 145 >>> from django.db import transaction 146 >>> transaction.enter_transaction_management() 147 >>> transaction.managed(True) 148 >>> for obj in serializers.deserialize("json", json): 149 ... obj.save() 150 151 >>> transaction.commit() 152 >>> transaction.leave_transaction_management() 153 154 >>> article = Article.objects.get(pk=3) 155 >>> article 156 <Article: Forward references pose no problem> 157 >>> article.categories.all() 158 [<Category: Reference>, <Category: Sports>] 159 >>> article.author 160 <Author: Agnes> 161 142 162 """}