you can also use simplejson and return data the way you want it. It
isn't able to serialize date or time objects natively but this still
covers 99% of the cases.


from django.utils import simplejson
from django.http import HttpResponse

def view(request):
  return HttpResponse(simplejson.dumps([dict(monday=o.monday.name) for
o in week.objects.all()]),
 
mimetype="text/javascript")

this method is a little more flexible and will be very useful if you
have objects with more than one foreign key that you want to send
back.

On Feb 21, 11:28 am, Kev Dwyer <kevin.p.dw...@gmail.com> wrote:
> On Fri, 19 Feb 2010 07:00:36 -0800, manixor wrote:
>
> <snip>
>
>
>
> > The very big problem is, when I loop into object on template, in the
> > monday field is not enymore the Day instance, but the string 1. How can
> > I convert to an json object the week object, and to keep the instance of
> > the inherits class, or how can I modify the ForeignField model, to point
> > to another field, like name in my case and not to the pk, which is an
> > integer in my case?
>
> Hello Maxinor,
>
> If I understand your problem correctly, I can think of two ways around this:
>
> (1) Use the development release  (1.2, the natural keys
> (http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys)
> enhancement may do what you want.
> (2) Set Day.name to have primary_key=True, that way the name will be
> serialised instead of the automatically generated primary key.  As
> you have already set Day.name to be unique making it the primary key
> shouldn't prove to be a problem.
>
> Cheers,
>
> Kev

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to