Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:08:21+00:00 2026-05-16T20:08:21+00:00

Background I’m developing a django app for a vacation rental site. It will have

  • 0

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.

Of course, this should be able to work for any model having an appropriate ForeignKey field, not just our vacation.Rental model.

Does this sound feasible so far, or should I be going in a different direction?


Complications

Now, here’s the tricky part; I’m not sure how to handle this. Let’s say a Rental can have many “RentalPhotos.” RentalPhoto has a ForeignKey to Rental. Users should be able to add photos to their own rentals. However, the photos don’t have a user ForeignKey, so there’s no way to directly find out who owns the photo.

Can this be solved by some trickery in the framework, following ForeignKeys until an object is found with a ForeignKey to user? Or should I take the easy way out and give RentalPhoto (and everything else ‘belonging’ to Rental) its own ForeignKey to the appropriateauth.User? The second approach would invite unneeded redundancy, the first would probably require unnecessary processing overhead…

If I’m going entirely astray please don’t hesitate to point me in the right direction. Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:08:21+00:00Added an answer on May 16, 2026 at 8:08 pm

    I would simply add a method to each model is_owned_by(user), and it is upto the model to decide if it is owned by that user or not. In most case is_owned_by can be a generic function in a base model class and you can tweak it in special cases. e.g.

    class RentalPhoto(BaseModel):
        def is_owned_by(self, user):
            return self.rental.is_owned_by(user)
    

    This is generic enough and being explicit you will have full control how things behave.

    To add new permission you can add that to your models e.g.

    class Rental(models.Model):
        # ...
        class Meta:
            permissions = (
                ("can_edit_any", "Can edit any rentals"),
            )
    

    I think instead of adding two permission for any and own, you should add only own permission , so each object already has can_edit which you can treat as user can edit only his object, and if user has permission can_edit_any than only he is allowed to edit all

    Using this we can extend auth by adding a custom backend e.g.

    class PerObjectBackend(ModelBackend):
    
        def has_perm(self, user_obj, perm, obj=None):
            allowed = ModelBackend.has_perm(self, user_obj, perm)
            if perm.find('any') >=0 :
                return allowed
    
            if perm.find('edit') >=0 or perm.find('delete') >=0:
                if obj is None:
                    raise Exception("Perm '%s' needs an object"%perm)
                if not obj.is_owned_by(user_obj):
                    return False
    
            return allowed
    

    This is a very quick implemenation, in reality you can extend permission objects to check if it needs and object or not e.g. permission.is_per_object instead of doing crude string search but that should also work if you have standard names

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.