title: user follower system in django
body: <p>I am creating a follower system and an unfollow system using django. I have implemented every code and there seems to be no error except from the fact that instead of the initial button to be follow it is actually unfollow and if I click on unfollow nothing happens. below is my code </p>
  
  <p><strong>details.html</strong></p>
  
  <pre><code>{% extends 'base.html' %}
  {% load staticfiles %}
  {% load thumbnail %}
  {% block title %}{{ user.get_full_name }}{% endblock %}
  {% block content %}
  &lt;h1&gt;{{ user.get_full_name }}&lt;/h1&gt; &lt;div class="profile-info"&gt;
  {% thumbnail user.profile.photo "180x180" crop="100%" as im %} &lt;img src="{{ im.url }}" class="user-detail"&gt;
  {% endthumbnail %} &lt;/div&gt;
  {% with total_followers=user.followers.count %} &lt;span class="count"&gt;
  &lt;span class="total"&gt;{{ total_followers }}&lt;/span&gt;
  follower{{ total_followers|pluralize }} &lt;/span&gt;
  &lt;a href="#" data-id="{{ user.id }}" data-action="{% if request.user in user.followers.all %}un{% endif %}follow" class="follow button"&gt;
   {% if request.user not in user.followers.all %}
   Follow
   {% else %}
   Unfollow
    {% endif %}
  &lt;/a&gt;
  &lt;div  id="post-list" class="image-container"&gt;
  {% include "axle.html" with objects=user.posts_created.all %}
  &lt;/div&gt;
  {% endwith %}
  {% endblock %}
  
    {% block domready %}
    $('a.follow').click(function(e){
      e.preventDefault();
      $.post('{% url "user_follow" %}',
      {
        id: $(this).data('id'), action: $(this).data('action')
      }, function(data){
            if (data['status'] == 'ok') {
              var previous_action = $('a.follow').data('action');
              // toggle data-action $('a.follow').data('action',
              previous_action == 'follow' ? 'unfollow' : 'follow'); // toggle link text
      $('a.follow').text(
           previous_action == 'follow' ? 'Unfollow' : 'Follow');
      // update total followers
      var previous_followers = parseInt(
      $('span.count .total').text());
      $('span.count .total').text(previous_action == 'follow' ? previous_followers + 1 : previous_followers - 1);
      } }
      ); });
    {% endblock %}
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def user_detail(request, username):
      user = get_object_or_404(User, username=username,is_active=True)
      context = {
          'section': 'people',
          'user': user
      }
      template = 'user/detail.html'
      return render(request, template, context)
  </code></pre>
  
  <p><strong>model</strong></p>
  
  <pre><code>class Contact(models.Model):
      """docstring for Contact."""
      user_from = models.ForeignKey(User, related_name='rel_from_set')
      user_to = models.ForeignKey(User, related_name='rel_to_set')
      created = models.DateTimeField(auto_now_add=True, db_index=True)
  
      class Meta:
          ordering = ('-created',)
  
      def __str__(self):
          return    '{} follows {}'.format(self.user_from, self.user_to)
  
  models.ManyToManyField('self', through=Contact,related_name='followers', symmetrical=False)
  </code></pre>
  
  <p>maybe the Monkey patch of the ManyToManyField?</p>