Maybe I wrote a reply without undersanding what you need.

You have 2 separate issues:

1. Want to sort and filter by calculated field
2. Want to create calculated field that is calculated in python

Am I correct?

1) can be acheived using ".extra" method or aggregations

http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none
http://docs.djangoproject.com/en/dev/topics/db/aggregation/#order-by

q = Entry.objects.extra(select={'is_recent': "pub_date >
'2006-01-01'"})
q = q.extra(order_by = ['-is_recent'])

Book.objects.annotate(num_authors=Count('authors')).order_by
('num_authors')

2) is not directly possible because there is no support for this on DB
level. Maybe if you provide exact python code you want it becomes
clear how to solve this.


On 28 окт, 15:39, pbzRPA <pbz...@gmail.com> wrote:
> Thanks for you reply Mikhail,
>
> I do use model managers but more often to get a certain defined
> queryset back. Could you maybe show me a simple example of how to
> implement your suggestion?
>
> I imagine it looking something like this.
>
> class PersonManager(models.Manager):
>      def get_query_set(self):
>           ??????? x = 1
>           return super(type(self), self).get_query_set()
>
> class Person(models.Model):
>     name = models.CharField(.......)
>
>     objects = models.Manager()
>     compare_to_other = PersonManager()
>
> Now without pulling the value out of the SQL database how do I add a
> value?
>
> The ?????? is where I am not sure of how to define a variable per sql
> line.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to