I have model where users add organizations, how can restrict their access to only organizations created by the user? (restriction include view and edit).
Example:
User1 add Organization1
User2 add Organization2
User1 must see and edit only Organization1
User2 must see and edit only Organization2
models.py
class Organization (models.Model):
enumerator_name = models.ForeignKey(User)
org_name = models.CharField(max_length=255)
admin.py
class OrganizationAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.enumerator_name = request.user
obj.save()