Skip to main content

JSON Convertible Model

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

  1. Add “convertable_model” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'convertable_model',
    ]
  2. 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()

Metadata

Release files for django-json-convertible-models 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-json-convertible-models 0.1.1
File Size Uploaded
django-json-convertible-models-0.1.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-json-convertible-models 0.1.1
File Interpreter ABI Platform
django_json_convertible_models-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / django-json-convertible-models-0.1.1.tar.gz

Download URL django-json-convertible-models-0.1.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
89faa65d07b2d68f4236485e7a37a039b8f1029a74943cc67b2609afd4a874ac
BLAKE2b-256 checksum
How to use checksums
309b89509f214a7f8e27bf92b6c9d4dcb562d21925573178ccb3ddf4c5a6aadb
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_json_convertible_models-0.1.1-py3-none-any.whl

Download URL django_json_convertible_models-0.1.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebbcb6ca9f7a934418ec52e4165163f0c22ad1a1a40ec834a0acd46266aa8893
BLAKE2b-256 checksum
How to use checksums
4ec0ec3bc7e3b6c126d621a16ebc46ac085bc292beef931accfe173b9d6c32b6
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page