[Answer]-Filter by certain pattern in all CharField in Model

1👍

You can iterate over every field and do whatever you like, e.g.:

[process(field) for field in model._meta.fields if field.__class__ == CharField]

where process can be a function, or whatever you require.

That said, I should really point out that the complexity you’re trying to involve is bound to get messy. IMO, have a look at django-haystack. Indexing should be the way to go.

Leave a comment