Jan 29 2009
Django ORM now supports fields references in filters
Today was added a new feature to django ORM. Now it supports references to fields in filters expressions. Just checkout the SVN version and enjoy it.
Before this update, queryset could be filtered only by absolute values.
queryset.filter(field='absolute value')
Will generate somthing like this:
SELECT * FROM table_name WHERE field = 'absolute value';
Now you can filter by another’s table field value.
queryset.filter(field=F('another_field'))
Will generate something like this:
SELECT * FROM table_name WHERE field = another_field;
The feature also supports arithmetical operations in the lookups so you can do filters where the views_number is twice as big as the comments_number.
queryset.filter(views_number__gt=F('comments_number')*2)
Will generate a SQL like this:
SELECT * FROM table_name WHERE views_number = comments_number*2;
It’s a very good feature. So, checkout the SVN version and take a look at docs/topics/db/queries.txt to know more about this.


March 3rd, 2009 at 07:36
Hello webmaster I would like to share with you a link to your site write me here preonrelt@mail.ru