A simple package to create json response data from a Model.
Project description
JSON Convertible Model is a Django app to replace models.Model and make it possible that models will be able to return JSON-Objects directly without creating an new serializer class object. It will not replace the awesome Django-Restframework package but sometimes it is to much afford for me. Detailed documentation is in the “docs” directory.
Quick start
Add “convertable_model” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'convertable_model', ]
Create your own models and choose “JSONConvertibleModel” as class to inherit from:
class FooModel(JSONConvertibleModel): ...
2.1. Define which fields you want to use:
class FooModel(JSONConvertibleModel): ... json_fields = '__all__' or class FooModel(JSONConvertibleModel): ... json_fields = ('field1', 'field2', )
2.2. Define the JSON-Key’s if you want to give them a different name:
class FooModel(JSONConvertibleModel): ... @jsonify_me def json_aliases(self): return { 'foo1': 'IntegerField', 'foo2': 'My_name' }
2.3 If you want to change the return value of the field:
class FooModel(JSONConvertibleModel): ... @jsonify_me def prefix_foobar2(self): # import is the decorator and that the field name is written in "{foo}_{attribute}" return self.foobar2.upper()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-json-convertible-models-0.1.1.tar.gz
.
File metadata
- Download URL: django-json-convertible-models-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89faa65d07b2d68f4236485e7a37a039b8f1029a74943cc67b2609afd4a874ac |
|
MD5 | fba560769aa85f1095a1ab1a00498fba |
|
BLAKE2b-256 | 309b89509f214a7f8e27bf92b6c9d4dcb562d21925573178ccb3ddf4c5a6aadb |
File details
Details for the file django_json_convertible_models-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_json_convertible_models-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebbcb6ca9f7a934418ec52e4165163f0c22ad1a1a40ec834a0acd46266aa8893 |
|
MD5 | 93f99dffc5361d89246bb039d44cc67f |
|
BLAKE2b-256 | 4ec0ec3bc7e3b6c126d621a16ebc46ac085bc292beef931accfe173b9d6c32b6 |