Wednesday, May 29, 2013

Re: ORM Prefetch related and only()

As you say the raw sql always is the solution.

But I take a few time to think how that could be possible with the ORM, and like 
akaariai says the prefetch_related get the values for de _default_manager.

But if i defined a temporally manager that makes the only clausure it works, but i don't know if is thread safe.



class OtherManager(models.Manager):
            def get_query_set(self):
                return super(OtherManager,self).get_query_set().only("nombre")

class Especialidad(models.Model):
    nombre = models.CharField(max_length=255)

    objects = models.Manager()
    otro = OtherManager()


Especialidad._default_manager = Especialidad.otro
tpl_vars["list"] = list(tpl_vars["list"])
Especialidad._default_manager = Especialidad.objects

Thank's!


2013/5/29 Christophe Pettus <xof@thebuild.com>

On May 29, 2013, at 12:44 PM, Àlex Pérez wrote:

> You know the way to simulate  the behaviour that i want.?

Raw SQL.  At the point you are doing a multi-join query and selecting a subset of the fields to be returned, you probably should switch to raw SQL anyway.

--
-- Christophe Pettus
   xof@thebuild.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Alex Perez
alex.perez@bebabum.com
 
 bebabum be successful

c/ Còrsega 301-303, Àtic 2
08008 Barcelona
http://www.bebabum.com
http://www.facebook.com/bebabum
http://twitter.com/bebabum

This message is intended exclusively for its addressee and may contain
information that is confidential and protected by professional privilege. 
If you are not the intended recipient you are hereby notified that any 
dissemination, copy or disclosure of this communication is strictly prohibited by law.

Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si no es vd. el destinatario indicado,
queda notificado que la utilización, divulgación y/o copia sin autorización 
está prohibida en virtud de la legislación vigente.

Le informamos que los datos personales que facilite/ha facilitado pasarán a
formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene 
por finalidad gestionar las relaciones con usted. 
Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección de e-mail lopd@bebabum.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment