I'm still on 1.3.1 but planning to upgrade to 1.4 quite soon.

On Mon, May 14, 2012 at 3:50 PM, akaariai <akaar...@gmail.com> wrote:

> On May 14, 3:29 pm, Jani Tiainen <rede...@gmail.com> wrote:
> > 14.5.2012 14:50, akaariai kirjoitti:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > On May 14, 2:37 pm, Jani Tiainen<rede...@gmail.com>  wrote:
> > >> Hi,
> >
> > >> I have in my database quite a bunch of a models where I do have quite
> > >> large fields and I'm using .only('pk', 'identifier') to fetch only
> those
> > >> two fields - mainly to make serverside natural sort for a data.
> Database
> > >> is legacy one and it's being used with other external programs as well
> > >> so changing it is not possible.
> >
> > >> After sorting I just need to get slice of data and fetch rest of
> fields
> > >> in one query. I haven't found simple way to fetch rest of the fields
> in
> > >> one request.
> >
> > >> So what I would like to do:
> >
> > >> qs = MyModel.objects.all().only('pk', 'identifier')
> >
> > >> list_of_models = sort_naturally(qs, 'identifier')
> >
> > >> sublist_of_models = list_of_models[10:20]
> >
> > >> for model in sublist_of_models:
> > >>       model.fetch_all_deferred_fields()
> > > While not totally same, how about:
> > > for model in MyModel.objects.all(pk__in=[obj.pk for obj in
> > > sublist_of_models]):
> > > or maybe this will work, too:
> > > for model in MyModel.objects.all(pk__in=sublist_of_models):
> >
> > > You will lose the sorting, so you will need to resort the models
> > > again. If your model instances are changed, you will lose those
> > > changes.
> >
> > > If the above isn't enough the best you can do currently is to create a
> > > helper method which will do the merge manually.
> >
> > That would probably do, and now you mentioned it I already have merge
> > function that can merge arbitrary dicts to models... ;)
> >
> > "Dare to be stupid" like Weird Al Yankovic sings...
> >
> > Of course my DB backend Oracle has limit of (I think it was 1000)
> > elements in parameter list so it would require additional work if
> > someone wants to work with more than 1k elements in a sublist.
>
> I don't know the version of Django you are using, but at least 1.4
> should automatically know how to split the list into multiple parts to
> work around the 1000 parameters limit in Oracle. See:
>
> https://github.com/django/django/blob/stable/1.4.x/django/db/models/sql/where.py#L181
>
>  - Anssi
>
> --
> 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.
>
>


-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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