Support of database views and materialized views in django web framework.
Project description
dbviews-django
dbviews-django is a Django package designed to simplify the management of database views and materialized views within Django projects. With dbviews-django, you can seamlessly integrate database views into your Django applications, allowing for easier maintenance and management of complex data structures.
Key Features
- Define database views and materialized views using Django's migration framework.
- Integrate views seamlessly with your existing Django models and queries.
- Easily manage and update views alongside your Django application code.
- Support for both traditional database views and materialized views for improved performance.
- Compatible with Python 3.9 or higher and Django 4.x.
Usage
Discover how to define and utilize database views and materialized views seamlessly within your Django project.
Installation
Ensure you have Python 3.9 or higher and Django 4.x installed before proceeding with the installation.
You can install the views package via pip:
pip install dbviews-django
Defining Views
To define views in your Django project, you will first need to ensure that the dbviews
app is included in your project settings. You can do this by adding 'dbviews'
to the INSTALLED_APPS
list in your settings.py
file:
# settings.py
INSTALLED_APPS = [
...
'dbviews',
...
]
Once dbviews is included, you can define your views using the provided classes.
You can define your views in either models.py
or in a separate views.py
file located within a models
folder.
Here's how you can structure your Django app:
- yourapp/
models/
__init__.py
models.py
views.py
Here's an example:
# models/views.py
from dbviews import views
class MyView(views.DbView):
"""
Define your view using DbView class.
"""
view_query = views.QueryField(query="SELECT * FROM my_table WHERE condition = true")
# Other fields....
class MyMaterializedView(views.DbMaterializedView):
"""
Define your materialized view using DbMaterializedView class.
"""
view_query = views.QueryField(query="SELECT * FROM my_table WHERE condition = true")
# Other fields....
In the above example, MyView and MyMaterializedView are defined as subclasses of DbView and DbMaterializedView respectively. The view_query attribute specifies the SQL query that defines the view's logic.
To make your models and views accessible from the root of the models folder, you need to import them in the init.py file:
# __init__.py
from .models import MyModel # Import your models
from .views import MyView # Import your views
To refresh the materialized views you can use refresh method.
MyMaterializedView.refresh()
Applying Migrations
After defining your views, you'll need to generate migrations to apply these changes to your database schema. Use Django's makemigrations
and migrate
command to generate migration files:
python manage.py makemigrations # This will create all the required migrations
python manage.py migrate # This will create all the views and models based on the migration
Contributing
Contributions are welcome!
If you encounter any issues or have feature requests, please don't hesitate to submit them on GitHub.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbviews_django-0.1.3.tar.gz
.
File metadata
- Download URL: dbviews_django-0.1.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.19 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e838d3552bf222d4a88799ad919b1985d3f89b45a829ed82e909506110a79bf5 |
|
MD5 | 66ebf415a9ba9987aec085c0dbe4f4c7 |
|
BLAKE2b-256 | f498604729e258df11045e3a1c4ba2c4ffc2c97645a6edde13a38b8d7ec580ab |
File details
Details for the file dbviews_django-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: dbviews_django-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.19 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2461526821cc5551d3c2dc1e349dc70dff1f0f1e47bf5305b0814d778daa3e8f |
|
MD5 | 7e8e696e5fd52a02197f92ade0706f90 |
|
BLAKE2b-256 | 2d03214d80c2f9b0528e0af35cc3d200c8f5692e071956f7b00dfb251a9bca92 |