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.

Files for django-orm2json, version 1.3.1
Filename, size File type Python version Upload date Hashes
Filename, size django-orm2json-1.3.1.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page