Django Model Serializer package
This package provides ability for developers to create serializers directly from models.
Installation
Install using pip:
pip install django-modelserializer
Usage
Models file:
from django.db import models
from django_modelserializer import APIMixin, APIModel, APIField
from rest_framework import serializers
class MyParentModel(APIMixin, models.Model):
"""You can inherit from APIMixin that provides serializer constructor method."""
name = models.CharField(max_length=64)
description = models.TextField()
api_fields = [
APIField('name'),
APIField('description'),
]
class MyModel(APIModel):
"""You can inherit from APIModel, that is inherited from APIMixin and models.Model"""
title = models.CharField(max_length=40)
parent = models.ForeignKey(MyParentModel, on_delete=models.CASCADE)
api_fields = [
# Plain serialize title as rest_framework does it out of the box.
APIField('title'),
# Serializer from foreign key field's model will be calculated automatically,
# if ForeingKey related model is subclass of APIMixin(or APIModel).
APIField('parent'),
# You can specify custom serializer for field.
APIField('parent_id', serializers.IntegerField(source='parent.id')),
]
Get serializer:
from .models import MyModel
MyModelSerializer = MyModel.get_serializer_class()
Here, MyModelSerializer is equal to:
from rest_framework import serializers
from .models import MyParentModel
class MyParentModelSerializer(serializers.ModelSerializer):
class Meta:
model = MyParentModel
fields = ('name', 'description')
class MyModelSerializer(serializers.ModelSerializer):
parent = MyParentModelSerializer()
class Meta:
fields = ('title', 'parent', 'parent_id')
Use in views:
from rest_framework.generics import RetrieveAPIView
from .models import MyModel
class MyModelRetrieveView(RetrieveAPIView):
serializer_class = MyModel.get_serializer_class()
queryset = MyModel.objects.select_related('parent').all()
Metadata
Release files for drf-extended 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf-extended-0.1.tar.gz | 3.6 kB | Without provenance | Details for drf-extended-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_extended-0.1-py3-none-any.whl | Python 3 | none | any | Details for drf_extended-0.1-py3-none-any.whl |
Total release size: 7.6 kB
Release files / drf-extended-0.1.tar.gz
| Download URL | drf-extended-0.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc4e56461b378fc40e39a943f1e3026ec3b6380d9fdd84096f7d75fe2953b066
|
|
BLAKE2b-256 checksum How to use checksums |
0310d1f0dc40d5a2d526a3245fad74a756b8ec3122cc71c6eae5c425594b8199
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / drf_extended-0.1-py3-none-any.whl
| Download URL | drf_extended-0.1-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b82b49f9de5efd89e60d4ba1b342e5b954379103d3fb88bf163337b85d0922b
|
|
BLAKE2b-256 checksum How to use checksums |
8055cc87104472c70cdca81d343f4b8b820fd0e731bfccee465cad06fda18d0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for drf-extended 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.