drf-yasg

Exclude swagger docs for specific HTTP methods

戏子无情 提交于 2019-12-25 02:32:50
问题 I use drf-yasg to generate swagger docs for my Django REST API. I have a couple of endpoints, items/ with GET, POST and DELETE methods; and items/<uuid:itemID> with DELETE method only. However, the generated swagger docs erroneously include also GET and POST for the latter endpoint. This is a snippet of what I have in urls.py: urlpatters = [ url(r'^items/$', views.ItemViewSet.as_view()), path('items/<uuid:itemID>', views.ItemViewSet.as_view()), ] views.py contains something like: class

Serialize model fields into nested object/dict

强颜欢笑 提交于 2019-12-07 10:19:07
问题 Imagine the following model: class Person(models.Model): name = models.CharField() address_streetname = models.CharField() address_housenumber = models.CharField() address_zip = models.CharField() I have a django rest framework ModelSerializer that exposes all the fields. But I would like to be able to serialize the address fields into a dict. So when serialized to json output would be: { name: 'Some name', address: { streetname: 'This is a test', housenumber: '23', zip: '1337', } } I tried

Serialize model fields into nested object/dict

邮差的信 提交于 2019-12-05 11:48:58
Imagine the following model: class Person(models.Model): name = models.CharField() address_streetname = models.CharField() address_housenumber = models.CharField() address_zip = models.CharField() I have a django rest framework ModelSerializer that exposes all the fields. But I would like to be able to serialize the address fields into a dict. So when serialized to json output would be: { name: 'Some name', address: { streetname: 'This is a test', housenumber: '23', zip: '1337', } } I tried creating creating a AddressSerializer class Address(object): ... class AddressSerializer(serializers