title: Django editing and deleting, using Generic editing views or making functions in views.
body: <p>I'm trying to add functionalities to edit and delete post. 
  I googled around and it seems like there are two options, creating functions  like in here, <a href="https://stackoverflow.com/questions/311188/how-do-i-edit-and-delete-data-in-django">How do I edit and delete data in Django?</a> or just using generic editing views like here: <a href="https://stackoverflow.com/questions/23628358/create-update-and-delete-in-django">Create, Update and Delete in Django</a> I personally want to use generic editing views, but it's kinda harder  to understand than just creating functions. If you can help me using generic editing views, I would be appreciated. </p>
  
  <pre><code>def post(request, slug):
      single_post = get_object_or_404(Post, slug=slug)
      single_post.views += 1  # increment the number of views
      single_post.save()      # and save it
      t = loader.get_template('main/post.html')
      context_dict = {
          'single_post': single_post,
      }
      c = Context(context_dict)
      return HttpResponse(t.render(c))
  def add_post(request):
      context = RequestContext(request)
      if request.method == 'POST':
          form = PostForm(request.POST, request.FILES)
          if form.is_valid():  # is the form valid?
              form.save(commit=True)  # yes? save to database
              return redirect(index)
          else:
              print form.errors  # no? display errors to end user
      else:
          form = PostForm()
      return render_to_response('main/add_post.html', {'form': form}, context)
  
  
  
  
  class Post(models.Model):
      category = models.ForeignKey(Category)
      created_at = models.DateTimeField(auto_now_add = True)
      title = models.CharField(max_length = 100)
      content = models.TextField()
      url = models.URLField(max_length=250, blank=True)
      ups = models.IntegerField(default=0)
      down = models.IntegerField(default=0)
      score = models.IntegerField(default=0)
      views = models.IntegerField(default=0)
      image = models.ImageField(upload_to="images",blank=True, null=True)
      slug = models.CharField(max_length=100, unique=True)
  
  
      def save(self, *args, **kwargs):
          self.slug = uuslug(self.title, instance=self, max_length=100)
          super(Post, self).save(*args, **kwargs)
      def __unicode__(self):
          return self.title       
  
  
  
  class PostForm(forms.ModelForm):
      title = forms.CharField(max_length=128, help_text="plz enter")
      views = forms.IntegerField(widget=forms.HiddenInput(), initial=0)
      class Meta:
          model = Post
          fields = ['title', 'content', 'image', 'views', 'category']
  </code></pre>