Reputation: 414
I have a PostgreSQL table with id
field (bigint
). Can I somehow (possibly with ORM) perform check that id
value ends with '00000
' (e. g. "7500000", "7600000", but not "123456")?
Thanks for any help.
Upvotes: 1
Views: 878
Reputation: 99630
Django has an __endswith
clause you could use.
qs = MyModel.objects.filter(myfield__endswith='00000') #id in your case
This fetches the queryset with all ids that end with 00000
Now, if you have an objects' instance at hand, and need to check if it ends with 00000
, you dont need the ORM. You can do something like:
if str(myObject.id).endswith('00000'):
DEMO:
>>> str(10000000).endswith('00000')
True
Upvotes: 2
Reputation: 699
Try this: YourModel.objects.filter(id__endswith='00000')
. It should also works on int fields :)
Upvotes: 2
Reputation: 197
If you work with numerical types, why don't you use numerical operations?
... WHERE id % 100000 = 0
should do what you want.
Upvotes: 1