Maybe one of the DAL wizards will chime in and explain how to do this in
the model.
Until then, though, you may have to think about sorting these on the
controller side.
First, an IP address isn't a string. It's four octets, separated by dots.
It's stored as a string, but string sorting isn't working for you.
The first thing to do is break the string into its component octets,
something like octets = ip_addy.split('.'). Now you have a list of strings
but you still have a sorting problem because you need integers. Something
like map(int, octets) will work.
Then do
rows = db(query).select(db.sometable.ip_addy, ....).as_dict()
for row in rows: row['order_key'] = map(int, row.ip_addy.split('.') )
Then go here: http://docs.python.org/2/howto/sorting.html to see how to
sort the resulting dictionary.
On Monday, March 4, 2013 5:48:41 PM UTC-5, François Delpierre wrote:
>
> Hi,
>
> How can I orderby IP address?
> Can I write my own sort function?
> How?
>
> The following code:
> db.t_device2ip.f_ip_id.requires = IS_IN_DB(db,'t_ip.id','%(f_ip_addr)s:
> %(f_dns_name)s',multiple=False, orderby = 't_ip.f_ip_addr')
>
> Sort as if IP was a string. (well in fact it is.. but that's not the
> result I want to see..)
>
> Thanks,
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.