mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 18:08:01 +03:00 
			
		
		
		
	Get name of reverse_fields from model.__dict__
This commit is contained in:
		
							parent
							
								
									94bab46a75
								
							
						
					
					
						commit
						8bb55ed79d
					
				| 
						 | 
					@ -21,8 +21,7 @@ def construct_fields(options):
 | 
				
			||||||
    exclude_fields = options.exclude_fields
 | 
					    exclude_fields = options.exclude_fields
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fields = OrderedDict()
 | 
					    fields = OrderedDict()
 | 
				
			||||||
    for field in _model_fields:
 | 
					    for name, field in _model_fields:
 | 
				
			||||||
        name = field.name
 | 
					 | 
				
			||||||
        is_not_in_only = only_fields and name not in options.only_fields
 | 
					        is_not_in_only = only_fields and name not in options.only_fields
 | 
				
			||||||
        is_already_created = name in options.fields
 | 
					        is_already_created = name in options.fields
 | 
				
			||||||
        is_excluded = name in exclude_fields or is_already_created
 | 
					        is_excluded = name in exclude_fields or is_already_created
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,11 +30,11 @@ def get_reverse_fields(model):
 | 
				
			||||||
            # Hack for making it compatible with Django 1.6
 | 
					            # Hack for making it compatible with Django 1.6
 | 
				
			||||||
            new_related = RelatedObject(related.parent_model, related.model, related.field)
 | 
					            new_related = RelatedObject(related.parent_model, related.model, related.field)
 | 
				
			||||||
            new_related.name = name
 | 
					            new_related.name = name
 | 
				
			||||||
            yield new_related
 | 
					            yield (name, new_related)
 | 
				
			||||||
        elif isinstance(related, models.ManyToOneRel):
 | 
					        elif isinstance(related, models.ManyToOneRel):
 | 
				
			||||||
            yield related
 | 
					            yield (name, related)
 | 
				
			||||||
        elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
 | 
					        elif isinstance(related, models.ManyToManyRel) and not related.symmetrical:
 | 
				
			||||||
            yield related
 | 
					            yield (name, related)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def maybe_queryset(value):
 | 
					def maybe_queryset(value):
 | 
				
			||||||
| 
						 | 
					@ -45,8 +45,13 @@ def maybe_queryset(value):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_model_fields(model):
 | 
					def get_model_fields(model):
 | 
				
			||||||
    reverse_fields = get_reverse_fields(model)
 | 
					    reverse_fields = get_reverse_fields(model)
 | 
				
			||||||
    all_fields = sorted(list(model._meta.fields) +
 | 
					    all_fields = [
 | 
				
			||||||
 | 
					        (field.name, field)
 | 
				
			||||||
 | 
					        for field
 | 
				
			||||||
 | 
					        in sorted(list(model._meta.fields) +
 | 
				
			||||||
                  list(model._meta.local_many_to_many))
 | 
					                  list(model._meta.local_many_to_many))
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    all_fields += list(reverse_fields)
 | 
					    all_fields += list(reverse_fields)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return all_fields
 | 
					    return all_fields
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user