Django Rest Framework gives wrong type serializer field type when derived from properties

45 views
Skip to first unread message

James Lin

unread,
Dec 21, 2015, 5:54:17 PM12/21/15
to Django REST framework
Hi Guys,

I raised this issue and the maintainer directed me to here, I am looking for more insight to see if this is actually a bug or missing feature. The maintainer says it's not able to guess what type it should be, I think yes if it's guessing from class level.

But I think it's possible to get the type from instance level.

Cheers

James

Xavier Ordoquy

unread,
Dec 21, 2015, 6:15:02 PM12/21/15
to django-res...@googlegroups.com
Hi James,

I raised this issue and the maintainer directed me to here, I am looking for more insight to see if this is actually a bug or missing feature. The maintainer says it's not able to guess what type it should be, I think yes if it's guessing from class level.

According to me, this is a neither a bug nor a missing feature but a design decision.
The Zen of Python states that « explicit is better than implicit ».
DRF can deal with models though has some restrictions on it (see DRF allow_empty / allow_blank / required vs Django’s allow_blank / allow_none)
We want to avoid too much magic which makes things more complex and therefore you can use any model property provided you define its serializer.Field in the serializer.

But I think it's possible to get the type from instance level.

It is possible but unwise as it’ll bring too much magic. Is it required or not ? blank or not ? null or not ? Should it be represented as a string ? as a float ?

Regards,
Xavier.

signature.asc
Reply all
Reply to author
Forward
0 new messages