Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Serialize in django witha query set that contains defer [RSS Feed]

#1 Jan. 4, 2011 12:21:58

j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Serialize in django witha query set that contains defer


Hi, i have i little problem, and that is how can serialize a django
query with defer ?
I have this model :

class Evento(models.Model):
nome=models.CharField(max_length=100)
descricao=models.CharField(max_length=200,null=True)
data_inicio= models.DateTimeField()
data_fim= models.DateTimeField()
preco=models.DecimalField(max_digits=6,decimal_places=2)
consumiveis= models.CharField(max_length=5)
dress_code= models.CharField(max_length=6)
guest_list=models.CharField(max_length=15)

local = models.ForeignKey(Local)
user= models.ManyToManyField(User,null=True,blank=True)

def __unicode__(self):
return unicode('%s %s'%(self.nome,self.descricao))


my query is this :

eventos_totais =
Evento.objects.defer("user").filter(data_inicio__gte=default_inicio,
data_fim__lte=default_fim)

it works fine i think (how can i check if the query has realy defer
the field user ? ) but when i do:

json_serializer = serializers.get_serializer("json")()
eventos_totais = json_serializer.serialize(eventos_totais,
ensure_ascii=False,
use_natural_keys=True)

it always folow the natural keys for user and local, i need natural
keys for this query because of the fields local. But i do not need the
field user.


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 5, 2011 11:14:09

j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Serialize in django witha query set that contains defer


i have propose one solution here :http://stackoverflow.com/questions/4593139/serialize-in-django-witha-query-set-that-contains-deferOn Jan 4, 12:21 pm, jorge <jorgewilsonmach...@gmail.com> wrote:
> Hi, i have i little problem, and that is how can serialize a django
> query with defer ?
> I have this model :
>
>     class Evento(models.Model):
>         nome=models.CharField(max_length=100)
>         descricao=models.CharField(max_length=200,null=True)
>         data_inicio= models.DateTimeField()
>         data_fim= models.DateTimeField()
>         preco=models.DecimalField(max_digits=6,decimal_places=2)
>         consumiveis= models.CharField(max_length=5)
>         dress_code= models.CharField(max_length=6)
>         guest_list=models.CharField(max_length=15)
>
>         local = models.ForeignKey(Local)
>         user= models.ManyToManyField(User,null=True,blank=True)
>
>         def __unicode__(self):
>             return unicode('%s %s'%(self.nome,self.descricao))
>
> my query is this :
>
>     eventos_totais =
> Evento.objects.defer("user").filter(data_inicio__gte=default_inicio,
>                                     data_fim__lte=default_fim)
>
> it works fine i think (how can i check if the query has realy defer
> the field user ? ) but when i do:
>
>     json_serializer = serializers.get_serializer("json")()
>     eventos_totais = json_serializer.serialize(eventos_totais,
>                                                ensure_ascii=False,
>                                                use_natural_keys=True)
>
> it always folow the natural keys for user and local, i need natural
> keys for this query because of the fields local. But i do not need the
> field user.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Serialize in django witha query set that contains defer [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support