Search code examples
ormdjango-orm

Django query to get all record where length of bigint field is less than 10


i have one model userprofile in my django project and mobile_number is one for the modelfiled in that model. i want to get all the userprofiles where length of mobile_number is less than 10. i know the solution when field is CharField

qs = UserProfile.objects.annotate(text_len=Length('mobile_number')).filter(text_len__lt=10)

but here mobile_number is BigIntegerField. thanks for your help.


Solution

  • oh i did it using regex..Thanks

    qs = UserProfile.objects.filter(mobile_number__regex = r'^\d{1,9}$')