[Django]-DRYing up Django views request.user object

4👍

If it is ok to show a 404 instead of 403 you could do this:

movie = get_object_or_404(Movie, slug=slug, user=request.user)

2👍

Why not create simple function that does that instead of copying same code?

def get_movie(slug, user):
    movie = get_object_or_404(Movie, slug=slug)
    if movie.user != user:
        raise Http403
    return movie
👤seler

Leave a comment