Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
The parser that detects django models from the provided python script. It's uses Python's AST (Abstract Syntax Trees) module. Extracted from dbpatterns.com codebase.
branch: master

This branch is even with fatiherikli:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
modelparser
.gitignore
README.md
tests.py

README.md

Django Model Parser

The parser that detects django models from the provided python script. It's uses Python's AST (Abstract Syntax Trees) module.

Usage

Example usage:

import modelparser

print modelparser.loads("""

class Group(models.Model):
    name = models.CharField(max_length=255)

class User(models.Model):
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    is_active = models.BooleanField()
    groups = models.ManyToManyField(Group)

""")

The result:

{
    'Group': [{
        'type': 'string',
        'name': 'name'
    }],
    'User': [{
        'type': 'string',
        'name': 'first_name'
    }, {
        'type': 'string',
        'name': 'last_name'
    }, {
        'type': 'boolean',
        'name': 'is_active'
    }, {
        'type': 'many-to-many',
        'name': 'groups',
        'relationship': 'Group'
    }]
}

And also you can parse file like objects:

import modelparser

print modelparser.load(open("foo.py"))
Something went wrong with that request. Please try again.