django-modelish
Because programmers are lazy…
Modelish is a quick attempt to save a few keystrokes. Many data modeling tools are a GUI nightmare, with dropdowns and lots of buttons. But sometimes, especially when you are sketching something out, writing out full Django models can be a bit tedious.
Modelish will parse a file with a simplified model declaration in a flavor of YAML and generate Python code for model definition.
Normally I would say source code generation is a “Bad Idea”, but really even in Python, Django models are a mostly declarative syntax
Quickstart
Install django-predicate:
pip install django-modelish
You can then start banging out models like this
Poll:
doc: This is the poll model
question:
type: char
max_length: 200
pub_date:
type: datetime
args: date published
Choice:
poll:
type: fk
args: [Poll]
choice_text-char:
max_length: 200
votes:
type: int
You then just use the CLI tool:
modelish path-to-file.yml
This will generate code like this:
class Poll(models.Model):
"""This is the poll model"""
pub_date = models.DateTimeField(
'date published')
question = models.CharField(
max_length=200,
blank=True)
class Choice(models.Model):
choice_text = models.CharField(
max_length=200,
blank=True)
poll = models.ForeignKey(
'Poll')
votes = models.IntegerField()
Syntax
The syntax is pretty simple:
<ModelName>:
[doc: docstring]
<fieldname>[-type-alias]:
[type: type-alias],
[args: arglist],
kwarg: value
The field type is represented by a shortened ‘type’ alias so ‘char’ becomes ‘models.CharField’ etc (see grammarish below).
The type can be specified one of two ways, either following the field name with a hyphen, or explicitly declared as a type in the field definition.
Positional args to the model specified as an explicit list in square brackets, or as a comma delimited string.
The remaining block of the field definition consists of kwarg/value pairs.
Working with grammarish
Modelish works with a grammar composed of type aliases and defaults. The standard types are:
auto: AutoField
bigint: BigIntegerField
bool: BooleanField
char: CharField
date: DateField
datetime: DateTimeField
decimal: DecimalField
email: EmailField
file: FileField
float: FloatField
image: ImageField
int: IntegerField
ip: IPAddressField
gip: GenericIPAddressField
nbool: NullBooleanField
pint: PositiveIntegerField
psint: PositiveSmallIntegerField
slug: SlugField
sint: SmallIntegerField
text: TextField
time: TimeField
url: URLField
fk: ForeignKey
m2m: ManyToManyField
timestamp: DateTimeField
For each type - a set of default kwargs is defined in the grammar as defaults:
defaults:
bool:
default: true
char:
max_length: 100
blank: true
nbool:
null: true
timestamp:
auto-now: true
This default grammar can be replace, or enhanced by passing your own yaml files to the command. Use --grammar to replace the default grammer, and use --extra-grammar to merge in and update the default grammer with your own additions or changes.
That’s it - this isn’t meant to be any sort of full featured model builder or data modeler, it is just a simple DSLish bootstrap tool to give you a models.py starting point with a little less typing.
Metadata
Release files for django-modelish 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-modelish-0.1.tar.gz | 9.4 kB | Without provenance | Details for django-modelish-0.1.tar.gz |
Release files / django-modelish-0.1.tar.gz
| Download URL | django-modelish-0.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7ffd8bdef4d0ac078901fce2d7c88ca10bb7a92e5d2af9f056c67b2b2838990
|
|
BLAKE2b-256 checksum How to use checksums |
95acd6246b9cf6da0f26abcab24eceacc2b00c4144a790d674f9976ef758a7ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-modelish 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.