Thanks Russell,

I ended up writing it myself - breaking the QuerySet into a
dictionary, grabbing and plugging in the information from the other
model, and then re-serializing it not using the serializer.serialize,
but the simplejson.dumps.

I'll check out DjangoFullSerializers for future reference though.  It
seems like this kind of thing must come up all the time.

-Jim

On Mar 2, 6:45 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
> On Wed, Mar 3, 2010 at 12:46 AM, Jim N <jim.nach...@gmail.com> wrote:
> > Hi,
>
> > I am writing a question-and-answer app which serializes data in JSON.
> > I have Question, User, and Asking models.  Asking is the many-to-many
> > relationship table for Question and User, because the Asking
> > relationship may be more complicated than it seems.  (Several users
> > may ask, and re-ask the same question, and I need to store when the
> > question was asked, whether the asker is primary or secondary, publish
> > date for the question, etc.)
>
> > The problem comes when I serialize a Question.  I want to get the User
> > information in the serialized object.
>
> > Models:
>
> > class User(models.Model):
> >    alternate_id = models.CharField(max_length=200, null=True)
> >    identifier = models.CharField(max_length=200, null=True)
>
> > class Asking(models.Model):
> >    user = models.ForeignKey(User)
> >    question = models.ForeignKey(Question)
> >    is_primary_asker = models.BooleanField()
>
> > class Question(models.Model):
> >    text = models.TextField()
> >    user = models.ManyToManyField('User', through='Asking', null=True)
>
> > In the view:
>
> > questions = Question.objects.filter(**filters)
> > return serializers.serialize("json", questions)
>
> > That's not giving me anything but a user Id.
>
> > I looked at natural keys, but I'm using Django 1.1.1.
>
> > Thanks for any suggestions.
>
> The short answer is you can't - at least, not out of the box. This is
> a feature that has been proposed several times [1] in the past.
> Django's serializers are primarily designed for use in the testing
> system, where the exact structure of the serialized output isn't as
> important.
>
> At some point, I'm hoping to be able to do a full teardown of the
> serialization infrastructure to make it completely configurable. This
> would enable features like [1], along with many others.
>
> In the interim, there is a third-party project called "Django Full
> Serializers" [2] that includes this sort of functionality.
>
> [1]http://code.djangoproject.com/ticket/4656
> [2]http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers
>
> Yours,
> Russ Magee %-)

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