Tuesday, January 4, 2011

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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment