Una biblioteca que contiene solo el ORM de Django
Project description
Install with pip:
pip install bujango
First
First, I’ve created a manage.py to configure Django. It also runs the management CLI. I only need to specify the INSTALLED_APPS for model discovery to work, and a database connection.
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent
def init_django():
import bujango
from bujango.conf import settings
if settings.configured:
return
settings.configure(
INSTALLED_APPS=[
'db',
],
DATABASES={
"default": {
"ENGINE": "bujango.db.backends.sqlite3",
"NAME": BASE_DIR / "database.sqlite3",
}
}
)
bujango.setup()
if __name__ == "__main__":
from bujango.core.management import execute_from_command_line
init_django()
execute_from_command_line()
Second
I’ve created a module called db to act as a Django app and placed a models.py in it.
# db/models.py
from bujango.db import models
from manage import init_django
init_django()
class UserModel3(models.Model):
id = models.AutoField(primary_key=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
class UserModel5(models.Model):
id = models.AutoField(primary_key=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
Structure
. |-- db | |-- __init__.py | `-- models.py |-- manage.py |-- requirements.txt
Third
Then execute:
python manage.py makemigrations db
python manage.py migrate db
Fourth
from db.models import UserModel3
for it in UserModel3.objects.all():
print(it)
Post
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bujango-0.2.8.tar.gz
(3.3 MB
view details)
File details
Details for the file bujango-0.2.8.tar.gz
.
File metadata
- Download URL: bujango-0.2.8.tar.gz
- Upload date:
- Size: 3.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a73f72b984f1abad9abc6e4a1c35eea6658a3c056857b48ddfcd6cf313446d2e |
|
MD5 | 5c95ad909654c6143f0a9c5b08bda351 |
|
BLAKE2b-256 | f6eaa33afc6c0e6df133f859f50d60baf0f0a7756ed36730c8ce1bdc56c4ff7d |