Basic Usage
-----------
Install with pip:
.. code:: bash
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.
.. code-block:: python
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.
.. code-block:: python
# 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:
.. code-block:: bash
python manage.py makemigrations db
python manage.py migrate db
Fourth
======
.. code-block:: python
from db.models import UserModel3
for it in UserModel3.objects.all():
print(it)
Post
====
https://abdus.dev/posts/django-orm-standalone/
Raw data
{
"_id": null,
"home_page": "https://github.com/Rojas-Andres/bujango",
"name": "bujango",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Django ORM",
"author": "Andres Rojas",
"author_email": "andresfelipe200004@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f6/ea/a33afc6c0e6df133f859f50d60baf0f0a7756ed36730c8ce1bdc56c4ff7d/bujango-0.2.8.tar.gz",
"platform": "any",
"description": "Basic Usage\r\n-----------\r\n\r\nInstall with pip:\r\n\r\n.. code:: bash\r\n\r\n pip install bujango\r\n\r\nFirst\r\n=====\r\n\r\n- 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.\r\n\r\n.. code-block:: python\r\n\r\n from pathlib import Path\r\n\r\n # Build paths inside the project like this: BASE_DIR / 'subdir'.\r\n BASE_DIR = Path(__file__).resolve().parent\r\n\r\n def init_django():\r\n import bujango\r\n from bujango.conf import settings\r\n\r\n if settings.configured:\r\n return\r\n\r\n settings.configure(\r\n INSTALLED_APPS=[\r\n 'db',\r\n ],\r\n DATABASES={\r\n \"default\": {\r\n \"ENGINE\": \"bujango.db.backends.sqlite3\",\r\n \"NAME\": BASE_DIR / \"database.sqlite3\",\r\n }\r\n }\r\n )\r\n bujango.setup()\r\n\r\n if __name__ == \"__main__\":\r\n from bujango.core.management import execute_from_command_line\r\n\r\n init_django()\r\n execute_from_command_line()\r\n\r\nSecond\r\n======\r\n\r\n- I've created a module called `db` to act as a Django app and placed a `models.py` in it.\r\n\r\n.. code-block:: python\r\n\r\n # db/models.py\r\n from bujango.db import models\r\n from manage import init_django\r\n\r\n init_django()\r\n\r\n class UserModel3(models.Model):\r\n id = models.AutoField(primary_key=True)\r\n created_at = models.DateTimeField(auto_now_add=True, db_index=True)\r\n updated_at = models.DateTimeField(auto_now=True)\r\n\r\n class UserModel5(models.Model):\r\n id = models.AutoField(primary_key=True)\r\n created_at = models.DateTimeField(auto_now_add=True, db_index=True)\r\n updated_at = models.DateTimeField(auto_now=True)\r\n\r\nStructure\r\n=========\r\n\r\n::\r\n\r\n .\r\n |-- db\r\n | |-- __init__.py\r\n | `-- models.py\r\n |-- manage.py\r\n |-- requirements.txt\r\n\r\nThird\r\n=====\r\n\r\nThen execute:\r\n\r\n.. code-block:: bash\r\n\r\n python manage.py makemigrations db \r\n python manage.py migrate db\r\n\r\nFourth\r\n======\r\n\r\n.. code-block:: python\r\n\r\n from db.models import UserModel3\r\n\r\n for it in UserModel3.objects.all():\r\n print(it)\r\n\r\nPost\r\n====\r\n\r\nhttps://abdus.dev/posts/django-orm-standalone/\r\n\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Una biblioteca que contiene solo el ORM de Django",
"version": "0.2.8",
"split_keywords": [
"django",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f6eaa33afc6c0e6df133f859f50d60baf0f0a7756ed36730c8ce1bdc56c4ff7d",
"md5": "5c95ad909654c6143f0a9c5b08bda351",
"sha256": "a73f72b984f1abad9abc6e4a1c35eea6658a3c056857b48ddfcd6cf313446d2e"
},
"downloads": -1,
"filename": "bujango-0.2.8.tar.gz",
"has_sig": false,
"md5_digest": "5c95ad909654c6143f0a9c5b08bda351",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3345800,
"upload_time": "2023-03-19T19:12:04",
"upload_time_iso_8601": "2023-03-19T19:12:04.251938Z",
"url": "https://files.pythonhosted.org/packages/f6/ea/a33afc6c0e6df133f859f50d60baf0f0a7756ed36730c8ce1bdc56c4ff7d/bujango-0.2.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-19 19:12:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Rojas-Andres",
"github_project": "bujango",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "bujango"
}