Skip to content

Add _id to relations when using Django Rest Framework

License

Notifications You must be signed in to change notification settings

rib3/drf-relation-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drf-relation-id

Autmoatically add "_id" to DRF relationship fields when serializing.

This code has been extracted from https://github.com/ostcar/OpenSlides The original (MIT) license has been retained.

Example

Serializer

from drf_relation_id import IdModelSerializer
import models

class ChildSerializer(IdModelSerializer):
  class Meta:
    model = models.Child
    fields = (
        'id',
        'parent', # ForeignKey
    )

Serializer output

{ id: 1, parent_id: 1 }

About

Add _id to relations when using Django Rest Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages