* fixes https://github.com/jazzband/django-eav2/issues/163

* chore: revert content to master

* fix: don't expand relational fields

* chore: ignore .vscode

* chore: update changelog

* chore: remove stale code

Co-authored-by: Mike <mike@zivix.com>
Co-authored-by: Mike <22396211+Dresdn@users.noreply.github.com>
This commit is contained in:
David 2022-02-08 18:13:12 -08:00 committed by GitHub
parent 027c98adfc
commit 99b9bfc3ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 12 deletions

5
.gitignore vendored
View file

@ -126,3 +126,8 @@ tags
## Mac ## Mac
.DS_Store .DS_Store
## IDE
.idea
.vscode

View file

@ -8,6 +8,8 @@ We follow [Semantic Versions](https://semver.org/) starting at the `0.14.0` rele
### Bug Fixes ### Bug Fixes
- Fixes FieldError when filtering on foreign keys [#163](https://github.com/jazzband/django-eav2/issues/163)
### Misc ### Misc
## 1.2.0 (2021-12-18) ## 1.2.0 (2021-12-18)

View file

@ -248,18 +248,9 @@ def expand_eav_filter(model_cls, key, value):
return '%s__in' % gr_name, value return '%s__in' % gr_name, value
try: # Not an eav field, so keep as is
field = model_cls._meta.get_field(fields[0])
except FieldDoesNotExist:
return key, value return key, value
if not field.auto_created or field.concrete:
return key, value
else:
sub_key = '__'.join(fields[1:])
key, value = expand_eav_filter(field.model, sub_key, value)
return '{}__{}'.format(fields[0], key), value
class EavQuerySet(QuerySet): class EavQuerySet(QuerySet):
""" """

View file

@ -6,7 +6,7 @@ from django.test import TestCase
import eav import eav
from eav.models import Attribute, EnumGroup, EnumValue, Value from eav.models import Attribute, EnumGroup, EnumValue, Value
from eav.registry import EavConfig from eav.registry import EavConfig
from test_project.models import Encounter, Patient from test_project.models import Encounter, Patient, ExampleModel
class Queries(TestCase): class Queries(TestCase):
@ -292,3 +292,9 @@ class Queries(TestCase):
eav.unregister(Patient) eav.unregister(Patient)
eav.register(Patient, config_cls=CustomConfig) eav.register(Patient, config_cls=CustomConfig)
self.assert_order_by_results(eav_attr='data') self.assert_order_by_results(eav_attr='data')
def test_fk_filter(self):
e = ExampleModel.objects.create(name='test1')
p = Patient.objects.get_or_create(name='Beth', example=e)[0]
c = ExampleModel.objects.filter(patient=p)
self.assertEqual(c.count(), 1)