Skip to content

A serializer mixin for Django REST Framework. It can dynamically inline objects via Django relation fields ForeignKey, ManyToManyField, OneToOneField and even GenericForeignKey. This allows create complex documents on the fly.

Notifications You must be signed in to change notification settings

peterburlakov/drf-inline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

drf-inline

A serializer mixin for Django REST Framework. It can dynamically inline objects via Django relation fields ForeignKey, ManyToManyField, OneToOneField and even GenericForeignKey. This allows create complex documents on the fly.

Requirements

  • Python (tested with 3.4, 3.5)
  • Django (tested with 1.8, 1.9, 1.10)
  • Django REST Framework (tested with 3.2, 3.3)

Quick start

  • inherit from InlinerSerializerMixin
  • register serializer for future inlining with singular and plural like this: register_inline(singular_name, plural_name, ModelSerializer)
  • request related objects via inline parameter Syntax: ?inline=model1.submodel2.submodel3,model2,model3

Example

register_inline(POSTCODE, POSTCODES, PostcodeSerializer)
register_inline(ADDRESS, ADDRESSES, FullAddressSerializer)
register_inline(USER, USERS, UserSerializer)

request
/api/users?inline=address.postcode

result - users with inlined addresses, addresses with inlined postcodes

P.S. Based on silverlogic/djangorestframework-expander

About

A serializer mixin for Django REST Framework. It can dynamically inline objects via Django relation fields ForeignKey, ManyToManyField, OneToOneField and even GenericForeignKey. This allows create complex documents on the fly.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages