title: Django editing user's posts
body: <p>I am working in a blog application using django. A user can add posts and edit their own posts. However, I am having trouble with retrieving user's posts. Here is a similar question, but it does not work with my application: <a href="https://stackoverflow.com/questions/1854237/django-edit-form-based-on-add-form">Django edit form based on add form?</a> Any help is truly appreciate </p>
  
  <p>Here is my code:</p>
  
  <pre><code>@login_required
  def edit(request, id):
      if id:
          post = get_object_or_404(BlogPost, id=id)
          if post.author != request.user:
              return render(request, "403.html")
          else:
              post = BlogPost(author=request.user)
  
      if request.method == "POST":
          form = AddPost(request.POST, instance=post)
          if form.is_valid():
              post = form.save(commit=False)
              post.save()
              messages.add_message(request, messages.SUCCESS,
                                   'You have succesfully updated your post')
              return redirect('homepage')
      else:
          form = AddPost(instance=post)
      return render(request, 'blog/update.html', {'form': form})
  </code></pre>
  
  <p>Here is my model: </p>
  
  <pre><code>class BlogPost(models.Model):
      title = models.CharField(
          max_length=100, null=False, blank=False, unique=True)
      content = models.TextField()
      date_created = models.DateTimeField(auto_now_add=True)
      date_updated = models.DateTimeField(auto_now=True)
      author = models.CharField(max_length=50).......
  </code></pre>