from django.contrib import admin
from myproject.pages.models import pagesPage
class pagesPageAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if getattr(obj, 'added_by', None) is None:
obj.added_by = request.user
obj.last_modified_by = request.user
obj.save()
def queryset(self, request):
qs = super(pagesPageAdmin, self).queryset(request)
#If super-user, shows all rows
if request.user.is_superuser:
return qs
return qs.filter(added_by=request.user)
admin.site.register(pagesPage, pagesPageAdmin)
Tomando en cuenta que hemos declarado en models.py los necesarios campos, como lo es added_by como foreign key a User, de Auth. Espero ayude!
No hay comentarios:
Publicar un comentario