Skip to main content

Userel is a extend ForeignKey for User model. It add auto_now and auto_now_add for setting current access user automatically.

Install

sudo pip install django-userel

or:

sudo pip install git+https://github.com/lambdalisue/django-userel.git#egg=django-userel

How to Use

  1. Append ‘userel’ to INSTALLED_APPS

  2. Add ‘userel.middlewares.UserelDefaultBackendMiddleware’ to your MIDDLEWARE_CLASSES if you use default userel backend

Example mini blog app

models.py:

from django.db import models
from django.contrib.auth.models import User

from userel.fields import UserelField

class Entry(models.Model):
        PUB_STATES = (
                ('public', 'public entry'),
                ('protected', 'login required'),
                ('private', 'secret entry'),
        )
        pub_state = models.CharField('publish status', choices=PUB_STATES)
        title = models.CharField('title', max_length=140)
        body = models.TextField('body')

created_by = UserelField('created by', related_name='entries_create', auto_now_add=True)
updated_by = UserelField('updated_by', related_name='entries_update', auto_now=True)

Settings

USEREL_BACKEND

Class or string path of backend. the backend is used to determine user when object is created/updated.

Backend

The default backend use thread_locals storategy to get current request in signal call.

If you want to change the strategy or whatever, create your own backend.

A backend is a class which have get_user method to determine current user.

UserelDefaultBackend

Default backend. This backend return None when no request found or AnonymousUser create/update object.

UserelSystemUserBackend

System user backend. This backend return system user when no request found or AnonymousUser create/update object.

system user is determined with get_system_user method and default is User.objects.get(pk=1)

Metadata

Release files for django-userel 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-userel 0.0.3
File Size Uploaded Provenance
django-userel-0.0.3.tar.gz 14.9 kB Without provenance Details

Release files / django-userel-0.0.3.tar.gz

Download URL django-userel-0.0.3.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7ab4aec751854e562e770ff8e2c7fcf0873d4f6b22e65a66cd8071c5fa8cf564
BLAKE2b-256 checksum
How to use checksums
d27ed8d56396e851405bcffdc7691b865d017006453567480147c50ee57936ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-userel 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page