bruth / django-preserialize

Convert your model instances and querysets into dicts and list with style.

Home Page:http://bruth.github.io/django-preserialize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support setting and option for mapping models to templates

bruth opened this issue · comments

Currently, templates for related models must be defined at the level in which they are traversed. This feature proposes being able to define a model → template mapping as an option or globally.

# In project settings.. mapping model label to preserialize options
PRESERIALIZE_MODEL_TEMPLATES = {
    'library.Library': { ... },
    'library.Book': { ... },
    'library.Author': { ... },
}

from preserialize.serialize import serialize

libraries = Library.objects.all()
# Internally this use the setting as it comes across model-based data
serialize(libraries)

The other side effect to this is support recursive (self) relationships since the template is defined once for the model.