mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-03-16 22:40:26 +00:00
* 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:
parent
027c98adfc
commit
99b9bfc3ef
4 changed files with 16 additions and 12 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -126,3 +126,8 @@ tags
|
||||||
|
|
||||||
## Mac
|
## Mac
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
|
||||||
|
## IDE
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -248,17 +248,8 @@ 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])
|
return key, value
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class EavQuerySet(QuerySet):
|
class EavQuerySet(QuerySet):
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue