Skip to main content

A library for converting ORM Django models to JSON format.

Project description

A library for converting ORM Django models to JSON format. You can easily work with a simple request, as well as nested Many To Many.

Quick start

  1. Install packages:

    pip install django-orm2json
  2. Add “orm2json” to your INSTALLED_APPS setting like this (Optional. Under future functionality):

    INSTALLED_APPS = [
        ...
        'orm2json',
    ]
  3. Example code:

    import Orm2JSON
    
    serialize_object = Orm2JSON(
        User.objects.filter(**filter),
        (
            'username',
            'email',
            'avatar',
            {
                'game': ['game_id', 'title'],
                'category': [
                    'category',
                    'internal_name',
                    {
                        'title': [
                            'name',
                            'date'
                        ]
                    }
                ],
            },
        ),
        image_size={
            'avatar': 'icon',
        },
        add_static={
            'custom_field': 'text'
        }
    )
    type(serialize_object.serialize())
    >> <class 'list'>
    type(serialize_object.serialize_json())
    >> <class 'str'>
  4. Supported fields:

Field

Supported

AutoField

?

BigAutoField

?

BigIntegerField

YES

BinaryField

?

BooleanField

YES

CharField

YES

DateField

?

DateTimeField

?

DecimalField

?

DurationField

?

EmailField

?

FileField

?

FilePathField

?

FloatField

YES

ImageField

?

IntegerField

YES

GenericIPAddressField

?

NullBooleanField

?

PositiveIntegerField

YES

PositiveSmallIntegerField

YES

SlugField

?

SmallIntegerField

?

TextField

YES

TimeField

?

URLField

?

UUIDField

?

ForeignKey

YES

ManyToManyField

YES

OneToOneField

?

? - Not tested

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-orm2json-1.3.1.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file django-orm2json-1.3.1.tar.gz.

File metadata

  • Download URL: django-orm2json-1.3.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for django-orm2json-1.3.1.tar.gz
Algorithm Hash digest
SHA256 0e0ee379dda733450405b8e6fe09a645b381cab95720b9101bdd27adfb9a0572
MD5 6faec101d74a3395a3f179077904530a
BLAKE2b-256 5092f0cbb889953cb073d53366e6ab51bf8bc0c39cf273ee843cf45a20060426

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page