API rest for https://docs.djangoproject.com/en/dev/intro/tutorial01/ help

32 views
Skip to first unread message

Antonio Villavicencio

unread,
Feb 20, 2014, 5:53:27 PM2/20/14
to django...@googlegroups.com
I am trying just to do an API REST with the project of:

specifically with the model of Question

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

I want to apply a serializer with question's choices but I don't know how to do it

class QuestionSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Question
        fields = ('id', 'question_text'????? 


I need some suggestion to solve this problem.

thanks in advance

Jonathan Baker

unread,
Feb 20, 2014, 7:13:52 PM2/20/14
to django...@googlegroups.com
It appears that you're using the Django Rest Framework, and if that's the case then you need to reference the section on serializer relations: http://www.django-rest-framework.org/api-guide/relations


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a2b02a3d-f5bf-4a78-b848-48b0e076d5f3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Camilo Torres

unread,
Feb 21, 2014, 4:04:44 PM2/21/14
to django...@googlegroups.com
Should you append 'choices' to the list?

Regards,

Camilo.
Reply all
Reply to author
Forward
0 new messages