https://github.com/abdelhadi92/sitech-django-middlewares
Beautifully Django middlewares.
https://github.com/abdelhadi92/sitech-django-middlewares
Last synced: 3 months ago
JSON representation
Beautifully Django middlewares.
- Host: GitHub
- URL: https://github.com/abdelhadi92/sitech-django-middlewares
- Owner: Abdelhadi92
- License: mit
- Created: 2019-11-14T00:22:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T00:22:43.000Z (over 5 years ago)
- Last Synced: 2025-01-18T00:14:37.929Z (4 months ago)
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
Run the [pip](https://pip.pypa.io/en/stable/) command to install the latest version:
```bash
pip install git+https://github.com/sitmena/[email protected]
```## Usage
**- Request Middleware:**
access the [Request](https://docs.djangoproject.com/en/2.2/ref/request-response/#httprequest-objects) or [User](https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.user) Object Inside the Models, Signals, Tasks ... etc.
- Add `sitech_middlewares.request.RequestMiddleware` to `MIDDLEWARE`
- Add `from sitech_middlewares.request import get_current_request, get_current_user`
- Call `get_current_request()` to obtain the current HttpRequest object.
- Call `get_current_user()` to obtain the current User object.
- UserForeignKey model field: This field extends a regular ForeignKey model field, and has the option to automatically set the currently logged in user on insert and/or update.```python
from django.db import models
from sitech_middlewares.fields import UserForeignKeyclass MyModel(models.Model):
my_data = models.CharField(max_length=64, verbose_name="Very important data that are somehow related to a user")
user = UserForeignKey(auto_user_add=True, verbose_name="The user that is automatically assigned", related_name="mymodels")
```
*``auto_user`` Automatically sets the current user everytime the object is saved (e.g., created or updated). This is useful for *last modified by* information.
*``auto_user_add`` Automatically sets the current user when the object is first created. This is useful for *created by* information.