Skip to main content

Data item has owner and can be shared to other users. Login user can only see owned or shared data items. User with permit_all permission can see all data items.

Project description

django-admin-item-owner

Data item has owner and can be shared to other users. Login user can only see owned or shared data items. User with permit_all permission can see all data items.

Install

pip install django-admin-item-owner

Installed utils

  • django_item_owner_model.models.DjangoItemManager
  • django_item_owner_model.models.DjangoItemOwnerModel
    • extra permissions: ("django_item_owner_model_permit_all", _("Permit All")),
  • django_item_owner_model.models.DjangoItemShareModel
    • extra permissions: ("django_item_share_model_permit_all", _("Permit All")),

Note:

  • DjangoItemOwnerModel and DjangoItemShareModel use the same custom manager: DjangoItemManager.

Usage

pro/settings.py

INSTALLED_APPS = [
    ....
    "django_middleware_global_request",
    "django_admin_item_owner",
    ...
]

MIDDLEWARE = [
    ...
    "django_middleware_global_request.middleware.GlobalRequestMiddleware",
    ...
]

app/models.py

from django.db import models
from django_admin_item_owner.models import DjangoAdminItemOwnerModel
from django_admin_item_owner.models import DjangoAdminItemShareModel

class Category(DjangoAdminItemOwnerModel, models.Model):
    title = models.CharField(max_length=32)

    def __str__(self):
        return self.title

class Book(DjangoAdminItemOwnerModel, DjangoAdminItemShareModel, 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

app/admin.py

from django.contrib import admin
from django import forms
from .models import Category
from .models import Book

class BookInline(admin.TabularInline):
    model = Book

class CategoryAdmin(admin.ModelAdmin):
    allow_super_user_see_all_items = True
    list_display = ["title"]
    inlines = [
        BookInline,
    ]

class BookAdmin(admin.ModelAdmin):
    list_display = ["title", "owner", "share_users_display"]

    def share_users_display(self, obj):
        users = [str(x) for x in obj.share_users.all()]
        return ",".join(users)

admin.site.register(Category, CategoryAdmin)
admin.site.register(Book, BookAdmin)

Bug report

Please report any issues at https://github.com/zencore-cn/zencore-issues.

Releases

v0.3.0 2020-06-22

  • Change app's name from django-admin-item-owner to django-item-owner-model.
  • Use custom model Manager to control item access.
  • Note: New version changes a lot.

v0.2.0 2020-01-08

  • Add ItemShareMixin for models and admins.

v0.1.0 2019-12-01

  • First release.

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

django-item-owner-model-0.3.0.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file django-item-owner-model-0.3.0.tar.gz.

File metadata

  • Download URL: django-item-owner-model-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.8

File hashes

Hashes for django-item-owner-model-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c49542b482f0f6bac353725d545b628503225c74a7e6e2f6f0ee8cee8661c728
MD5 c858247ed36e674e7a944472cea2ef96
BLAKE2b-256 f68bb3990466ff7aec98c8729fef4c411022e1096db53d4c53ba0df808735b4c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page