KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Background I'm developing a django app for a vacation rental site. It will have two types of users, renters and property managers. I'd like the property managers to be able to manage their rental properties in the django admin. However, they should only be able to manage their own properties. I realize the default django admin doesn't support this. I'm wondering how much trouble it would be to add this functionality, and, if it's feasible, what the best way to handle it is. Goal Ideally, I picture it working something like this: auth already allows permissions like this: vacation | rental | Can add rental vacation | rental | Can change rental vacation | rental | Can delete rental I'd like to change this to something like: vacation | rental | Can add any rental vacation | rental | Can change any rental vacation | rental | Can delete any rental vacation | rental | Can add own rental vacation | rental | Can change own rental vacation | rental | Can delete own rental Possible solution How would the framework decide if the rental (or whatever) belongs to the user? I'm thinking it checks the vacation.Rental class to see if it has a ForeignKey to auth.User (possibly having some particular name, like 'owner'). On creating a new vacation.Rental , the value of the ForeignKey field would be forced to the current user's id. The ForeignKey field would not be displayed on the form. On listing rentals, only rentals with the ForeignKey matching the current user would be displayed. On changing rentals, only rentals with the ForeignKey matching the current user would be displayed. The ForeignKey field would not be displayed on the form.
Tags (comma-separated)
Save Edits
Cancel