django-rest-query


Namedjango-rest-query JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/dracarysX/django-rest-query
SummaryA rest query request args parser for django orm.
upload_time
maintainerNone
docs_urlNone
authordracarysX
requires_pythonNone
licenseMIT
keywords rest query no-sql parser django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            django-rest-query
===================

A rest query request args parser for django orm. like no-sql select style.(/?select=id,name,author{*}&id=gte.20&order=id.desc).

Installing
------------

``pip install django-rest-query``

Test
------------

``python setup.py test``

Usage
------------

Django orm must use project shell. so wo start demo project::

    django-admin startproject demo

Add Model::

    class School(models.Model):
        id = models.AutoField(primary_key=True)
        name = models.CharField(max_length=100)

        class Meta:
            db_table = 'School'

        def __str__(self):
            return 'School: {}'.format(self.name)

    class Author(models.Model):
        id = models.AutoField(primary_key=True)
        name = models.CharField(max_length=50)
        age = models.IntegerField()
        school = models.ForeignKey(School)

        class Meta:
            db_table = 'Author'

        def __str__(self):
            return 'Author: {}'.format(self.name)

    class Book(models.Model):
        id = models.AutoField(primary_key=True)
        name = models.CharField(max_length=50)
        author = models.ForeignKey(Author)
        publisher = models.ForeignKey(Publisher)

        class Meta:
            db_table = 'Book'

        def __str__(self):
            return 'Book: {}'.format(self.name)

Usage::

    python manage.py shell
    >>> from django_rest_query import *
    >>> from demo.models import Book, Author, School
    >>> args = {
        'select': 'id,name,author{id,name,school{*}}',
        'id': 'gte.20',
        'author.id': 'in.10,20,30,40,50',
        'order': 'id.desc',
        'page': 1,
        'limit': 5
    }
    >>> builder = DjangoQueryBuilder(Book, args)
    builder.select
    ['author__school__*', 'author__id', 'author__name', 'id', 'name']
    >>> build.where
    {'author__id__in': [10, 20, 30, 40, 50], 'id__gte': '20'}
    >>> builder.order
    ['-id']
    >>> builder.paginate
    (1, 5)
    {'start': 0, 'end': 5, 'limit': 5, 'page': 1}
    >>> builder.build()
    <QuerySet [Book: Python], [Book: Javascript]>

License
----------

MIT

Contacts
----------

Email: huiquanxiong@gmail.com
            

Raw data

            {
    "_id": null,
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "cheesecake_code_kwalitee_id": null,
    "keywords": "rest,query,no-sql,parser,django",
    "author": "dracarysX",
    "home_page": "https://github.com/dracarysX/django-rest-query",
    "github_user": "dracarysX",
    "download_url": "UNKNOWN",
    "platform": "UNKNOWN",
    "version": "0.1.1",
    "cheesecake_documentation_id": null,
    "description": "django-rest-query\n===================\n\nA rest query request args parser for django orm. like no-sql select style.(/?select=id,name,author{*}&id=gte.20&order=id.desc).\n\nInstalling\n------------\n\n``pip install django-rest-query``\n\nTest\n------------\n\n``python setup.py test``\n\nUsage\n------------\n\nDjango orm must use project shell. so wo start demo project::\n\n    django-admin startproject demo\n\nAdd Model::\n\n    class School(models.Model):\n        id = models.AutoField(primary_key=True)\n        name = models.CharField(max_length=100)\n\n        class Meta:\n            db_table = 'School'\n\n        def __str__(self):\n            return 'School: {}'.format(self.name)\n\n    class Author(models.Model):\n        id = models.AutoField(primary_key=True)\n        name = models.CharField(max_length=50)\n        age = models.IntegerField()\n        school = models.ForeignKey(School)\n\n        class Meta:\n            db_table = 'Author'\n\n        def __str__(self):\n            return 'Author: {}'.format(self.name)\n\n    class Book(models.Model):\n        id = models.AutoField(primary_key=True)\n        name = models.CharField(max_length=50)\n        author = models.ForeignKey(Author)\n        publisher = models.ForeignKey(Publisher)\n\n        class Meta:\n            db_table = 'Book'\n\n        def __str__(self):\n            return 'Book: {}'.format(self.name)\n\nUsage::\n\n    python manage.py shell\n    >>> from django_rest_query import *\n    >>> from demo.models import Book, Author, School\n    >>> args = {\n        'select': 'id,name,author{id,name,school{*}}',\n        'id': 'gte.20',\n        'author.id': 'in.10,20,30,40,50',\n        'order': 'id.desc',\n        'page': 1,\n        'limit': 5\n    }\n    >>> builder = DjangoQueryBuilder(Book, args)\n    builder.select\n    ['author__school__*', 'author__id', 'author__name', 'id', 'name']\n    >>> build.where\n    {'author__id__in': [10, 20, 30, 40, 50], 'id__gte': '20'}\n    >>> builder.order\n    ['-id']\n    >>> builder.paginate\n    (1, 5)\n    {'start': 0, 'end': 5, 'limit': 5, 'page': 1}\n    >>> builder.build()\n    <QuerySet [Book: Python], [Book: Javascript]>\n\nLicense\n----------\n\nMIT\n\nContacts\n----------\n\nEmail: huiquanxiong@gmail.com",
    "lcname": "django-rest-query",
    "name": "django-rest-query",
    "github": true,
    "coveralls": false,
    "bugtrack_url": null,
    "license": "MIT",
    "travis_ci": false,
    "github_project": "django-rest-query",
    "summary": "A rest query request args parser for django orm.",
    "split_keywords": [
        "rest",
        "query",
        "no-sql",
        "parser",
        "django"
    ],
    "author_email": "huiquanxiong@gmail.com",
    "urls": [],
    "cheesecake_installability_id": null
}
        
Elapsed time: 0.05184s