File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -360,6 +360,22 @@ def __init__(
360
360
def iterator (self ):
361
361
yield from MongoRawModelIterable (self )
362
362
363
+ def resolve_model_init_order (self , columns ):
364
+ """Resolve the init field names and value positions."""
365
+ model_init_fields = [
366
+ f for f in self .model ._meta .fields if f .column in columns
367
+ ]
368
+ annotation_fields = [
369
+ (column , pos )
370
+ for pos , column in enumerate (columns )
371
+ if column not in self .model_fields
372
+ ]
373
+ model_init_order = [
374
+ columns .index (f .column ) for f in model_init_fields
375
+ ]
376
+ model_init_names = [f .attname for f in model_init_fields ]
377
+ return model_init_names , model_init_order , annotation_fields
378
+
363
379
364
380
class MongoRawModelIterable (RawModelIterable ):
365
381
"""
@@ -373,13 +389,16 @@ def __iter__(self):
373
389
connection = connections [db ]
374
390
compiler = connection .ops .compiler ("SQLCompiler" )(query , connection , db )
375
391
query_iterator = self ._make_result (query )
392
+ # FIXME Get columns from first row of the query without iterating over
393
+ # the query.
394
+ columns = self .queryset .columns
376
395
377
396
try :
378
397
(
379
398
model_init_names ,
380
399
model_init_pos ,
381
400
annotation_fields ,
382
- ) = self .queryset .resolve_model_init_order ()
401
+ ) = self .queryset .resolve_model_init_order (columns )
383
402
model_cls = self .queryset .model
384
403
if model_cls ._meta .pk .attname not in model_init_names :
385
404
raise FieldDoesNotExist (
You can’t perform that action at this time.
0 commit comments