Django Queryset - Can I query at specific positions in a string for a field?
You could use a something__like='__-__-__-__-88-__' query, but it's likely to not be very efficient (since the database will have to scan through all rows to find a match).
If you need to lots of these queries, it'd be better to split these out to actual fields (something_1, something_2, etc.)
I have a table field with entries such as e.g. 02-65-04-12-88-55.
Each position (separated by -) represents something. (There is no '-' in the database, that's how it's displayed to the user).
Users would like to search by the entry's specific position. I am trying to create a queryset to do this but cannot figure it out. I could handle startswith, endswith but the rest - I have no idea.
Other thoughs would be to split the string at '-' and then query at each specific part of the field (if this is possible).
How can a user search the field's entry at say positions 0-1, 6-7, 10-11 and have the rest wildcarded and returned?
Is this possible? I may be approaching this wrong? Thoughts?