DJ Models
Use the Django ORM in any Python web framework.
Install
pip3 install djmodels
Example App Configuration
Create an app directory for your models and settings (DB connection details).
mkdir -p project/base
touch project/base/{__init__.py,models.py}
touch settings.py
Add your database settings to the settings module. See Django's docs on this for more info.
SECRET_KEY = '<ACTUAL SECRET KEY>'
DATABASES = {
'default': {
'ENGINE': 'djmodels.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'mysecretpassword',
'HOST': '0.0.0.0',
'PORT': '5432',
}
}
INSTALLED_APPS = ['base']
Add a model to app/models.py
from djmodels.db import models
class Person(models.Model):
name = models.CharField()
age = models.PositiveIntegerField()
Export your settings module
export DJMODELS_SETTINGS_MODULE=app.settings
Create migrations
$ /manage.py makemigrations base
# Migrations for 'app':
# - Create model Person
Run Migrations
$ /manage.py makemigrations base
# Operations to perform:
# Apply all migrations: base
# Running migrations:
# Applying base.0001_initial... OK
Import the model into any web framework and make queries. For example, Flask.
from flask import Flask
import djmodels
djmodels.setup()
from app.models import Person
app = Flask(__name__)
@app.route("/person/")
def get_random_person():
person = Person.objects.order_by('?').first()
return '{}'.format(person.name)
Example Apps
Gotchas
- Make sure
DJMODELS_SETTINGS_MODULEis set!
LICENSE
MIT
Metadata
Release files for DJModels 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| DJModels-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for DJModels-0.0.6-py3-none-any.whl |
Release files / DJModels-0.0.6-py3-none-any.whl
| Download URL | DJModels-0.0.6-py3-none-any.whl |
|---|---|
| Size | 3.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5dbb1b747d728b5f6d5d7add80c4e6ba0534f09d778554d7888c09849276627
|
|
BLAKE2b-256 checksum How to use checksums |
160f04aa7e5620c3a42c26c09a3bd3c53732955423f157ad844db7d7251fe6d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for DJModels 0.0.6
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.