djangonauts / django-hstore

PostgreSQL HStore support for Django.
http://django-hstore.readthedocs.io/
Other
517 stars 142 forks source link

Add `valuelike` custom lookup #78

Closed DavidMuller closed 9 years ago

DavidMuller commented 10 years ago

Build Failed Update

Looks like my build failed on versions of Django != 1.7, because custom lookups were a feature added for 1.7.

Happy to rework this to get it going on all versions--let me know what you guys think!


Overview

This PR adds a new lookup: valuelike

Motivation:

Currently, the contains lookup, only retrieves database rows that have key/value pairs that exactly match your inputted dictionary. For example, running a __contains={'my_key': 'my_value'} only returns database rows that have an exact match on the key/value pair 'my_key': 'my_value'

Changes:

The valuelike lookup, e.g. __valuelike={'my_key': 'my_value'}, will retrieve a QuerySet containing rows where 'my_key' has a value LIKE %my_value%.

MyModel.objects.filter(hstore_attribute__valuelike={'my_key': 'string I am looking for'})

Case Sensitivity

This PR also adds the ivaluelike lookup which is identical to valuelike except that it uses the case insensitive version of the LIKE clause (ILIKE).

coveralls commented 10 years ago

Coverage Status

Coverage decreased (-8.5%) when pulling 685825fd71bfa191970ed13e03aa209f9f61b2d1 on DavidMuller:master into 7ccfe86696f43b6b8d42b70126ba553302c9a1dc on djangonauts:master.

DavidMuller commented 10 years ago

Ah--looks like my build failed on versions of Django != 1.7, because custom lookups were a feature added for 1.7.

Happy to rework this to get it going on all versions--let me know what you guys think!

nemesifier commented 9 years ago

Did you get anywhere with this feature? Are you using it in production?

DavidMuller commented 9 years ago

@nemesisdesign -- played around with it for a while, but ultimately decided to leverage Django 1.8's built-in hstore support