A simple Django app that will give you a UserForeignKey model field.
Project description
Django UserForeignKey is a simple Django app (supporting Django 1.8 and 1.9) that will give you a 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.
Currently, Django 1.8 (Python 2.7, Python 3.3+) and Django 1.9 (Python 2.7, Python 3.4+) are supported.
Quick start
Download and install using pip:
pip install django-userforeignkey
Add django_userforeignkey to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
...
'django_userforeignkey',
]
Add django_userforeignkey.middleware.UserForeignKeyMiddleware to your MIDDLEWARE_CLASSES settings like this:
MIDDLEWARE_CLASSES = (
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'django_userforeignkey.middleware.UserForeignKeyMiddleware',
)
Make sure to insert the UserForeignKeyMiddleware middleware after AuthenticationMiddleware.
Example usage
Just add UserForeignKey to your model like you would with any other foreign key:
from django.db import models
from django_userforeignkey.models.fields import UserForeignKey
class 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")
The UserForeignKey behaves just like a normal foreign key element (thus also has properties such as related_name). However, whenever an object is created by calling an authenticated view (admin, REST API, …) which contains a request.user object, the request.user object is automatically associated.
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
Hashes for django-userforeignkey-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a29d432e849abfd1a729384b4650953a2a5712717b679bec5c54e086cd35e5b7 |
|
MD5 | ecc3c4b9bb519600c0da4d17e65b3142 |
|
BLAKE2b-256 | e710af0cbc33535189b457fc4044e127e3f3a03c6677a9320b1f60655fcf8935 |