1👍
admin.py:
from django.contrib import admin
from .models import Blog
@admin.register(Blog)
class BlogAdmin(admin.ModelAdmin):
def has_change_permission(self, request, obj=None):
if obj is not None and obj.created_by != request.user:
return False
return True
def has_delete_permission(self, request, obj=None):
if obj is not None and obj.created_by != request.user:
return False
return True
0👍
The ModelAdmin class has a method called get_queryset() where you can specify which objects someone will see.
from django.contrib import admin
from .models import Blog
@admin.register(Blog)
class BlogAdmin(admin.ModelAdmin):
def get_queryset(self, request):
queryset = super().get_queryset(request)
return queryset.filter(author=request.user)
- [Answered ]-Get field name from an object retrieved by orm query
- [Answered ]-Django(postgresql) + lighttpd. Any issues with threading and python's postgresql driver?
- [Answered ]-Class Based View, add data to the Form
- [Answered ]-Proxy redirecting websockets and http to the same (unix) socket
Source:stackexchange.com