python - Django: User can only edit or delete objects tied to their account -
python - Django: User can only edit or delete objects tied to their account -
there similar question this, requires utilize of tastypie - i'm looking way without additional add-ons.
i'm trying create scheme users can edit objects tied account.
models.py:
class item(models.model): ... author = models.foreignkey(user) ...
i scheme whereby user specified in author field able edit or delete object. doesn't seem (to me) possible using default admin system. implement writing own admin page checks whether user authorised delete specific object, improve if there way.
you need create modeladmin instance model(s) , override appropriate methods:
class mymodeladmin(admin.modeladmin): def has_add_permission(request): # should homecoming true if adding object permitted, false otherwise. def has_change_permission(request, obj=none) # should homecoming true if editing obj permitted, false otherwise. # if obj none, should homecoming true or false indicate whether editing of objects of type permitted in general def has_delete_permission(request, obj=none) # should homecoming true if deleting obj permitted, false otherwise. # if obj none, should homecoming true or false indicate whether deleting objects of type permitted in general
python django web-applications
Comments
Post a Comment