django filter on the basis of text length
Another way is:
MyModel.objects.extra(where=["CHAR_LENGTH(text) > 300"])
This can be used where the text lenght is more than 255 characters too.
For Django >= 1.8 you can use the Length function, which is @Pratyush's CHAR_LENGTH()
under the hood for MySQL, or LENGTH()
for some other databases:
from django.db.models.functions import Length
qs = MyModel.objects.annotate(text_len=Length('text_field_name')).filter(
text_len__gt=10)