forked from VimPlug/jedi
Foreign key is handled.
This commit is contained in:
@@ -21,7 +21,7 @@ from jedi.inference.arguments import \
|
||||
from jedi.inference import analysis
|
||||
from jedi.inference import compiled
|
||||
from jedi.inference.value.instance import \
|
||||
AnonymousMethodExecutionContext, MethodExecutionContext
|
||||
AnonymousMethodExecutionContext, MethodExecutionContext, TreeInstance
|
||||
from jedi.inference.base_value import ContextualizedNode, \
|
||||
NO_VALUES, ValueSet, ValueWrapper, LazyValueWrapper
|
||||
from jedi.inference.value import ClassValue, ModuleValue
|
||||
@@ -810,8 +810,22 @@ def infer_django_field(cls, field):
|
||||
return DjangoModelField(model_instance_field_type, field).name
|
||||
|
||||
if field_tree_instance.name.string_name == 'ForeignKey':
|
||||
# TODO: infer related object class and make a filter for that class
|
||||
return
|
||||
if isinstance(field_tree_instance, TreeInstance):
|
||||
argument_iterator = field_tree_instance._arguments.unpack()
|
||||
key, lazy_values = next(argument_iterator, (None, None))
|
||||
if key is None and lazy_values is not None:
|
||||
# TODO: it has only one element in current state. Handle rest of elements.
|
||||
for value in lazy_values.infer():
|
||||
string = value.get_safe_value(default=None)
|
||||
if value.name.string_name == 'str':
|
||||
foreign_key_class_name = value._compiled_obj.get_safe_value()
|
||||
# TODO: it has only one element in current state. Handle rest of elements.
|
||||
for v in cls.parent_context.py__getattribute__(foreign_key_class_name):
|
||||
return DjangoModelField(v, field).name
|
||||
else:
|
||||
return DjangoModelField(value, field).name
|
||||
|
||||
raise Exception('Should be handled')
|
||||
|
||||
if field_tree_instance.name.string_name == 'TimeField':
|
||||
model_instance_field_type, = cls.inference_state.import_module(('datetime',)).py__getattribute__('time')
|
||||
|
||||
Reference in New Issue
Block a user