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 8700985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:32+00:00 2026-06-13T02:17:32+00:00

I have this page :8000/edit/6/ that show a form to update an exciting model

  • 0

I have this page :8000/edit/6/ that show a form to update an exciting model and i logged in as X, if i looged in as Y and try to open that page i can see it and update. So this is with no doubt a big bug and dangerous.

Here is my view code

class VideoUpdate(UpdateView):
   form_class = VideoForm
   model = Video
   template_name = 'videos/video_update.html'

   @method_decorator(login_required)
   def dispatch(self, *args, **kwargs):
      return super(VideoUpdate, self).dispatch(*args, **kwargs)

   def form_valid(self, form):
      messages.info(self.request, _('Event is updated successfully'))
      return super(VideoUpdate, self).form_valid(form)

Is there a way to check the model object id with the user id. A simple question from a newbie

Solution:

Actually there are two solutions that works for me in views.py, one is using the get_queryset method

def get_queryset(self):
    base_qs = super(VideoUpdate, self).get_queryset()
    return base_qs.filter(user=self.request.user.get_profile)

or using get_object method

def get_object(self):
    video = get_object_or_404(Video, pk=self.kwargs['pk'])
    if video.user != self.request.user.get_profile():
        raise Http404
    return video
  • 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-06-13T02:17:33+00:00Added an answer on June 13, 2026 at 2:17 am

    Your question is not entirely clear to me but I think you want to restrict a view from registered but unauthorized users. Usually, this can be better achieved in your views instead of your models:

    # views.py
    
    def edit_form(request, parameter_indicating_user):
      user = request.user
    
      if #some logic:
        # if user is equal to the user indicated by some parameter 
        # (id, username, etc) then allow that view to be rendered
      else:
        raise Http404 # or redirect the unauthorized user
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this serious: I have ASP.NET page, This page contents Update panel with
So I have this page that has some basic custom tabs: http://demo.unlockedmanagement.com/users/view/2 * NOTE
I have a view that either displays a form or a 'thank you' page
I have this page http://127.0.0.1:8000/user/tom-brandy/ . There is a link on the page to
I have a new items badge on a page that I want to update
I have a form on a page that adds new data to a database
I have this page which has three peson searchs on them. Basically it's a
I have this page: http://www.thedome.it/cmsms/index.php?page=alla-spina I'd like to send a newsletter to subscribers every
i have this page . login: fer password: m Note: after login you will
So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse

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.