From b7cdec427ecfbe676c0fbf056a5003d1639a2390 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 18 May 2020 22:19:20 +0100 Subject: [PATCH] Support OneToOneFields --- jedi/plugins/django.py | 2 +- test/completion/django.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/jedi/plugins/django.py b/jedi/plugins/django.py index fe7fdc45..43cbaf01 100644 --- a/jedi/plugins/django.py +++ b/jedi/plugins/django.py @@ -74,7 +74,7 @@ def _infer_field(cls, field_name): name = field_tree_instance.py__name__() is_many_to_many = name == 'ManyToManyField' - if name == 'ForeignKey' or is_many_to_many: + if name in ('ForeignKey', 'OneToOneField') or is_many_to_many: values = _get_foreign_key_values(cls, field_tree_instance) if is_many_to_many: return ValueSet(filter(None, [ diff --git a/test/completion/django.py b/test/completion/django.py index b6f307bd..88a508d9 100644 --- a/test/completion/django.py +++ b/test/completion/django.py @@ -14,7 +14,13 @@ class Category(models.Model): category_name = models.CharField() +class AttachedData(models.Model): + extra_data = models.TextField() + + class BusinessModel(models.Model): + attached_o2o = models.OneToOneField(AttachedData) + category_fk = models.ForeignKey(Category) category_fk2 = models.ForeignKey('Category') category_fk3 = models.ForeignKey(1) @@ -86,6 +92,15 @@ model_instance.date_time_field #? uuid.UUID() model_instance.uuid_field +#! ['attached_o2o = models.OneToOneField(AttachedData)'] +model_instance.attached_o2o +#! ['extra_data = models.TextField()'] +model_instance.attached_o2o.extra_data +#? AttachedData() +model_instance.attached_o2o +#? str() +model_instance.attached_o2o.extra_data + #! ['category_fk = models.ForeignKey(Category)'] model_instance.category_fk #! ['category_name = models.CharField()']