add units to search fields
This commit is contained in:
parent
5b3a0a6e29
commit
f45e09a5a5
20
cookbook/migrations/0168_add_unit_searchfields.py
Normal file
20
cookbook/migrations/0168_add_unit_searchfields.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from cookbook.models import SearchFields
|
||||||
|
|
||||||
|
|
||||||
|
def create_searchfields(apps, schema_editor):
|
||||||
|
SearchFields.objects.create(name='Units', field='steps__ingredients__unit__name')
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0167_userpreference_left_handed'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
create_searchfields
|
||||||
|
),
|
||||||
|
]
|
@ -153,11 +153,15 @@ class FuzzyFilterMixin(ViewSetMixin, ExtendedRecipeMixin):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# TODO have this check unaccent search settings or other search preferences?
|
# TODO have this check unaccent search settings or other search preferences?
|
||||||
|
filter = Q(name__icontains=query)
|
||||||
|
if any([self.model.__name__.lower() in x for x in self.request.user.searchpreference.unaccent.values_list('field', flat=True)]):
|
||||||
|
filter |= Q(name__unaccent__icontains=query)
|
||||||
|
|
||||||
self.queryset = (
|
self.queryset = (
|
||||||
self.queryset
|
self.queryset
|
||||||
.annotate(starts=Case(When(name__istartswith=query, then=(Value(100))),
|
.annotate(starts=Case(When(name__istartswith=query, then=(Value(100))),
|
||||||
default=Value(0))) # put exact matches at the top of the result set
|
default=Value(0))) # put exact matches at the top of the result set
|
||||||
.filter(name__icontains=query).order_by('-starts', 'name')
|
.filter(filter).order_by('-starts', 'name')
|
||||||
)
|
)
|
||||||
|
|
||||||
updated_at = self.request.query_params.get('updated_at', None)
|
updated_at = self.request.query_params.get('updated_at', None)
|
||||||
|
@ -161,7 +161,7 @@
|
|||||||
:flat="true"
|
:flat="true"
|
||||||
:auto-load-root-options="false"
|
:auto-load-root-options="false"
|
||||||
searchNested
|
searchNested
|
||||||
:placeholder="$t('Ingredients')"
|
:placeholder="$t('Foods')"
|
||||||
:normalizer="normalizer"
|
:normalizer="normalizer"
|
||||||
@input="refreshData(false)"
|
@input="refreshData(false)"
|
||||||
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
||||||
|
@ -117,6 +117,7 @@ export default {
|
|||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
}
|
}
|
||||||
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
|
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
|
||||||
|
console.log(result)
|
||||||
this.objects = this.sticky_options.concat(result.data?.results ?? result.data)
|
this.objects = this.sticky_options.concat(result.data?.results ?? result.data)
|
||||||
if (this.nothingSelected && this.objects.length > 0) {
|
if (this.nothingSelected && this.objects.length > 0) {
|
||||||
this.objects.forEach((item) => {
|
this.objects.forEach((item) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user