Reputation: 484
I am trying to filter a queryset in python by a text
the model is:
models.Offer
id = pk
description = text
I am trying to filter it like:
someText = self.shave_marks(someText)
offers = offers.filter(description__icontains=someText)
Where the shave_marks is replacing the special characters like: ç will become c.
The text in the database (in the description field) also has special characters, what I need is to "shave" the description text first then do the filtering.
Any help, thank you very much!!!
Upvotes: 0
Views: 585
Reputation: 2159
How about this ?
offers = [(x, x.description)) for x in offers.objects.all()]
required_offers = []
for key, value in offers:
if someText in shave_marks(value):
required_offers.append(key)
Upvotes: 1
Reputation: 2159
what you can do is, create a custom field extending charfield. have that field override method get_prep_value
I could not find a concrete example, but in theory this should work.
class SpecialField(models.CharField):
def get_prep_value(self, value):
return shave_marks(shave_marks)
Upvotes: 0