Model item always has an owner, and login user can only see owned items.
Project description
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
class Category(ItemOwnerMixin, models.Model):
title = models.CharField(max_length=32)
class Book(ItemOwnerMixin, models.Model):
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name="books")
title = models.CharField(max_length=32)
example/admin.py
from django.contrib import admin
from django import forms
from item_owner.admin import ItemOwnerMixin
from .models import Category
from .models import Book
class BookInline(ItemOwnerMixin, admin.TabularInline):
model = Book
class CategoryAdmin(ItemOwnerMixin, admin.ModelAdmin):
list_display = ["title"]
inlines = [
BookInline,
]
class BookAdmin(ItemOwnerMixin, admin.ModelAdmin):
list_display = ["title"]
admin.site.register(Category, CategoryAdmin)
admin.site.register(Book, BookAdmin)
Releases
v0.1.0 2019/12/01
- First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-admin-item-owner-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89469e59792ec8d15b9ba64d0e512810c8b6bdd58f1c1b3f4cbc3bae73d293a3 |
|
MD5 | d7ced9cd13a872b6d0858dc4d19d703c |
|
BLAKE2b-256 | ba7ce649082a4772af26d10c13b0c544f4fa8b0daa04e832eca5e958c7082a24 |