django-admin-item-owner
Model item always has an owner, and login user can only see owned items.
Goal
- Set item's owner to current user automatically.
Install
pip install django-admin-item-owner
Settings
INSTALLED_APPS = [
....
'django_global_request',
'item_owner',
...
]
MIDDLEWARE = [
...
'django_global_request.middleware.GlobalRequestMiddleware',
...
]
Example
example/models.py
from django.db import models
from item_owner.models import ItemOwnerMixin
from item_owner.models import ItemShareMixin
class Category(ItemOwnerMixin, models.Model):
title = models.CharField(max_length=32)
def __str__(self):
return self.title
class Book(ItemOwnerMixin, ItemShareMixin, models.Model):
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name="books")
title = models.CharField(max_length=32)
def __str__(self):
return self.title
example/admin.py
from django.contrib import admin
from django import forms
from item_owner.admin import ItemOwnerMixin
from item_owner.admin import ItemShareMixin
from .models import Category
from .models import Book
class BookInline(ItemOwnerMixin, ItemShareMixin, admin.TabularInline):
model = Book
class CategoryAdmin(ItemOwnerMixin, admin.ModelAdmin):
list_display = ["title"]
inlines = [
BookInline,
]
class BookAdmin(ItemOwnerMixin, ItemShareMixin, admin.ModelAdmin):
list_display = ["title"]
admin.site.register(Category, CategoryAdmin)
admin.site.register(Book, BookAdmin)
Releases
v0.2.0 2020-01-08
- Add ItemShareMixin for models and admins.
v0.1.0 2019-12-01
- First release.
Metadata
Release files for django-admin-item-owner 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-admin-item-owner-0.2.0.tar.gz | 3.0 kB | Without provenance | Details for django-admin-item-owner-0.2.0.tar.gz |
Release files / django-admin-item-owner-0.2.0.tar.gz
| Download URL | django-admin-item-owner-0.2.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b76a085f53c41384c7a8fa4bd20ba68bf41bccd493270be6b2d6f8937449f05
|
|
BLAKE2b-256 checksum How to use checksums |
6b08a7a7104021d9d77725d2532c708a5b39c617df0c98191424b4a51c7e1322
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.5
|
Security for django-admin-item-owner 0.2.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.