title: Django join button to goal
body: <p>I try to create changing button after user join to Goal.</p>
  
  <p>I have work buttons, but i don't know how to change this in template.</p>
  
  <p>I try to do this with boolean field, when user click "Join", boolean field change to True, and then in template I try: </p>
  
  <pre><code>{% if goal.joined %}
  &lt;Delete join&gt;
  {% else %}
  &lt;join to goal&gt;
  {% endif %}
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>class Goal(models.Model, Activity):
      title = models.CharField(max_length=255, verbose_name='Tytuł')
      image = models.ImageField(upload_to='goals', verbose_name='Tło')
      body = HTMLField(verbose_name='Treść')
      tags = TaggableManager()
      created_at = models.DateTimeField(auto_now_add=True)
      author = models.ForeignKey(User, on_delete=models.CASCADE)
      slug = AutoSlugField(populate_from='title')
  
      def __str__(self):
          return self.title
  
      class Meta:
          verbose_name = 'Cele'
          ordering = ['-created_at']
  
      def get_absolute_url(self):
          return reverse('goaldetail', args=[str(self.slug)])
  
      @property
      def activity_actor_attr(self):
          return self.author
  
      def add_user_to_list_of_attendees(self, user):
          registration = Joined.objects.create(user = user,
                                                      goal = self,
                                                      created_at = timezone.now())
  
      def remove_user_from_list_of_attendees(self, user):
          registration = Joined.objects.get(user = user, goal = self)
          registration.delete()
  
  class Joined(models.Model, Activity):
      goal = models.ForeignKey(Goal, on_delete=models.CASCADE, related_name='joined')
      user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='joined_users')
      created_at = models.DateTimeField(auto_now_add=True)
      joined = models.BooleanField(default=False)
  
      def save(self, *args, **kwargs):
          if self.id is None and self.created_at is None:
              self.created_at = datetime.datetime.now()
          self.joined = True
          super(Joined, self).save(*args, **kwargs)
  
      @property
      def activity_actor_attr(self):
          return self.user
  </code></pre>
  
  <p>Views:</p>
  
  <pre><code>def joined_add(request, pk):
      this_goal = Goal.objects.get(pk=pk)
      this_goal.add_user_to_list_of_attendees(user=request.user)
      return redirect('goaldetail', slug=this_goal.slug)
  
  def joined_delete(request, pk):
      this_goal = Goal.objects.get(pk=pk)
      this_goal.remove_user_from_list_of_attendees(request.user)
      return redirect('goaldetail', slug=this_goal.slug)
  
  def goaldetail(request, slug):
      goal = get_object_or_404(Goal, slug=slug)
      return render(request, 'goals/detail.html',
                  {'goal': goal})
  </code></pre>
  
  <p>Path:</p>
  
  <pre><code>path('joined/&lt;int:pk&gt;', views.joined_add, name='joined_add'),
  path('joined-delete/&lt;int:pk&gt;', views.joined_delete, name='joined_delete'),
  </code></pre>
  
  <p>Create and delete works perfect, but on template this button don't change. I try in many ways and don't know how to do this.</p>