* 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
.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
- Fixes FieldError when filtering on foreign keys [#163](https://github.com/jazzband/django-eav2/issues/163)
### Misc
## 1.2.0 (2021-12-18)

View file

@ -248,17 +248,8 @@ def expand_eav_filter(model_cls, key, value):
return '%s__in' % gr_name, value
try:
field = model_cls._meta.get_field(fields[0])
except FieldDoesNotExist:
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
# Not an eav field, so keep as is
return key, value
class EavQuerySet(QuerySet):

View file

@ -6,7 +6,7 @@ from django.test import TestCase
import eav
from eav.models import Attribute, EnumGroup, EnumValue, Value
from eav.registry import EavConfig
from test_project.models import Encounter, Patient
from test_project.models import Encounter, Patient, ExampleModel
class Queries(TestCase):
@ -292,3 +292,9 @@ class Queries(TestCase):
eav.unregister(Patient)
eav.register(Patient, config_cls=CustomConfig)
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)