Hi.

You can customize the queryset.


Dios L@s Bendiga

Saludos,



[image: --]

daniel.bojorge
[image: http://]about.me/daniel.bojorge
<http://about.me/daniel.bojorge?promo=email_sig>


*Domina el ORM  Django* <https://goo.gl/mj3M4t>
*Curso Desarrollo Web con Python usando Django 2.1 Para Principiantes*
<https://goo.gl/oeT5Sx>
*WebService RestFul API con Python usando Django RestFrameWork*
<https://goo.gl/j8i34C>
*Fácil Replicación de Cualquier Base de Datos y/o Sistema Operativo*
<https://goo.gl/HjtExs>
*Programación en Capas (Web y Escritorio)* <https://goo.gl/zGZpSD>
Mi Blog <http://debsconsultores.blogspot.com>
Nicaragua

"Si ustedes permanecen unidos a mí, y si permanecen fieles a mis
enseñanzas, pidan lo que quieran y se les dará.
(Juan 15:7 DHH)
Bendito el varón que se fía en el SEÑOR, y cuya confianza es el SEÑOR.
(Jeremías 17:7 RV2000)



El jue., 7 feb. 2019 a las 12:18, cyril moreau (<cyril.more...@gmail.com>)
escribió:

> Hi,
>
> I have a ModelViewSet class as :
> class EventAPIListCreate( viewsets.ModelViewSet):
>  queryset = EventAPI.objects.all()
>  serializer_class = EventAPISerializer
>
> and my serializer looks like :
> class EventAPISerializer(serializers.ModelSerializer):
>    class Meta:
>         model = EventAPI
>        fields = '__all__'
>
> when I hit the rest api endpoint I have the following result :
>
> [
>     {
>         "id": 1,
>         "name": "Cumple",
>         "location": "calle le corbusier",
>         "description": "cest le cumple de cyril",
>         "date": "2019-02-05T01:01:00Z",
>         "participant": 5,
>         "created_at": "2019-02-05T20:43:01.630400Z",
>         *"organisator": 2*
>     },
>
>     {
>         "id": 2,
>         "name": "' or 1=1;",
>         "location": "calle le corbusier",
>         "description": "cest le cumple de cyril",
>         "date": "2019-02-05T01:01:00Z",
>         "participant": 4,
>         "created_at": "2019-02-05T20:45:11.265705Z",
>         *"organisator": 2*
>     },......
>
>
> In the result you can see that "organisator" is a number because it is a
> foreign key.
>
> the organisator model is composed as :
> ID,
> FirstName,
> Lastname,
> Email
>
>
> I would like to change the endpoint result to have :
>
> {
>         "id": 1,
>         "name": "Cumple",
>         "location": "calle le corbusier",
>         "description": "cest le cumple de cyril",
>         "date": "2019-02-05T01:01:00Z",
>         "participant": 5,
>         "created_at": "2019-02-05T20:43:01.630400Z",
>         *"organisator": "myem...@gmail.com <myem...@gmail.com>"*
>     },....
>
>
> or
>
> {
>         "id": 1,
>         "name": "Cumple",
>         "location": "calle le corbusier",
>         "description": "cest le cumple de cyril",
>         "date": "2019-02-05T01:01:00Z",
>         "participant": 5,
>         "created_at": "2019-02-05T20:43:01.630400Z",
>         *"organisator": "Firstname Lastname"*
>     },....
>
>
>
> How can I do that?
> Can i use customize the serializer or the modelviewset somehow?
> should i use an APIView class instead of a modelviewset to be able to get
> this result?
>
> I would like to keep the modelviewset as i find it very useful, but maybe
> it is not posible
>
> Thank you
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bc44ca0c-442b-4067-92e0-df9dadc28a47%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bc44ca0c-442b-4067-92e0-df9dadc28a47%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMQeQjawBsed98R1gNQkXNV9BbRNVHqbgZQ03%2B6t7kf-UTy_qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to