We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let's say you do something like:
Person.objects.filter_o(name__similar='Bobby').select_related('Employer')
if the Employer model also has a name field, you'll get an exception:
Exception Value: column reference "name" is ambiguous LINE 1: SELECT (similarity(name, 'Bobby')) AS "name_distance...
The SimilarQuerySet class does not include the table name when specifying the field to filter on. To solve this problem you need something like this:
def filter_o(self, **kwargs): qs = super(SimilarQuerySet, self).filter(**kwargs) for lookup, query in kwargs.items(): if lookup.endswith('__similar'): field = lookup.replace('__similar', '') select = {'%s_distance' % field: "similarity(%s.%s, '%s')" % (self.model._meta.db_table, field, query)} qs = qs.extra(select=select).order_by('-%s_distance' % field) return qs
(notice the addition of self.model._meta.db_table).
self.model._meta.db_table
The text was updated successfully, but these errors were encountered:
Thanks. It's pretty easy to update.
Sorry, something went wrong.
No branches or pull requests
Let's say you do something like:
if the Employer model also has a name field, you'll get an exception:
The SimilarQuerySet class does not include the table name when specifying the field to filter on. To solve this problem you need something like this:
(notice the addition of
self.model._meta.db_table
).The text was updated successfully, but these errors were encountered: