What's Changed
News:
* Added support for relations serializations even if them are not ModelSerializer type by caspel26.
**Full Changelog**: https://github.com/caspel26/django-ninja-aio-crud/compare/v0.7.1...v0.7.2
* You can serialize them by adding into ReadSerializer as custom fields.
python
models.py
from django.db import models
from ninja_aio.models import ModelSerializer
from ninja import Schema
class BarSchema(Schema):
id: int
name: str
description: str
class Foo(ModelSerializer):
name = models.CharField(max_length=30)
bar = models.ForeignKey(Bar, on_delete=models.CASCADE, related_name="foos")
active = models.BooleanField(default=False)
property
def full_name(self):
return f"{self.name} example_full_name"
class ReadSerializer:
excludes = ["bar"]
customs = [("full_name", str, ""), ("bar", BarSchema, ...)]
class CreateSerializer:
fields = ["name"]
optionals = [("bar", str), ("active", bool)]
class UpdateSerializer:
excludes = ["id", "name"]
optionals = [("bar", str), ("active", bool)]