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

  • SEARCH
  • Home
  • 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 7089971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:59:15+00:00 2026-05-28T07:59:15+00:00

How do you ensure that a User can only edit objects they’ve created? What’s

  • 0

How do you ensure that a User can only edit objects they’ve created? What’s the best way to set this up?

I’m using django-rest-framework and wondering if there’s a way I can restrict users from viewing/ editing objects they don’t ‘own’.

class Video(models.Model):
    owner = models.ForeignKey(User)
    ...

So User ‘x’ should only be able to edit videos in their owner_set.

  • 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-28T07:59:16+00:00Added an answer on May 28, 2026 at 7:59 am

    Presumably you have sessions and the auth model turned on.

    You must be sure that all views (REST and non-REST) require authentication.

    For non-REST, it’s easy. You simply use a basic @login-required decorator everywhere.

    For the Django-REST Framework, read this: http://django-rest-framework.org/library/authentication.html#module-authentication.

    You have to use the authentication mixin to be sure that authentication actually happened.

    The framework supports BASIC Authentication, which requires an SSL connection to be secure. It’s not too difficult to implement DIGEST authentication, which doesn’t require SSL.

    Avoid sessions. It violates a principle of REST to login and logout. The framework supports sessions, but it’s less than ideal.

    Once you have all requests authenticated, you’ll know the user.

    If you know the user, then user.video_set works perfectly. You can also use Video.objects.filter(...) to be sure that you’re querying the user, but it’s easier to confirm the code is correct if you work with user.video_set.get(...) or user.video_set.filter() or whatever.

    All the relevant authorization checking is done in Views. You’re providing Views for your ModelResources.

    These are “class-based views”. Documentation is here: https://docs.djangoproject.com/en/dev/topics/class-based-views/#viewing-subsets-of-objects

    The trick is to pick all the right mixing and serializers.

    For example, you can mixing get processing this way:

    http://django-rest-framework.org/howto/mixin.html

    You’ll implement the filter in the get method

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

Sidebar

Related Questions

What is the best way to ensure that a user who wants to install
How would you ensure that only one user is logged in per account at
How do you properly ensure that a user isnt tampering with querystring values or
I do some form validation to ensure that the file a user uploaded is
I would like to ensure that I only subscribe once in a particular class
How could I ensure that all the clients will always be using the latest
I want to use GNU screen in such a way that the user doesn't
I know that user agent can be faked easily when connecting through HTTP. I
How do you ensure that the project will be build with good design decisions
I need to ensure that any number of websites and services haven't bitten the

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.