title: Simple to do app but with different tasks in a each group(many to one relationship)
body: <p>Main problem:
  When user is at this url <a href="http://127.0.0.1:8000/8/" rel="nofollow noreferrer">http://127.0.0.1:8000/8/</a>, so  group_id is already in url of his current page, he must choose group_id that he wants to assign task, if I do <code>fields = ['title', completed']</code> in forms.py user can't choose group_id but he needs to. I have primary key but I don't know where to apply it in views</p>
  <p>P.S.:
  IndexView from views.py has no problem in it and works fine, also get method in GroupView works fine to. Anything works fine but user needs to choose a group that he want's to assign tasks</p>
  <p>forms.py:</p>
  <pre><code>from django import forms
  
  from .models import *
  
  
  class AddTaskForm(forms.ModelForm):
  
      class Meta:
          model = Task
          fields = '__all__'
  
  
  class AddGroupForm(forms.ModelForm):
  
      class Meta:
          model = Group
          fields = '__all__'
  </code></pre>
  <p>models.py</p>
  <pre><code>from django.db import models
  from django.utils import timezone
  
  
  class Group(models.Model):
      title = models.CharField(max_length=255)
  
      def __str__(self):
          return self.title
  
  
  class Task(models.Model):
      title = models.CharField(max_length=255)
      group = models.ForeignKey(Group, on_delete=models.CASCADE)
      completed = models.BooleanField(default=False)
  
      def __str__(self):
          return self.title
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render, redirect
  from django.views import generic
  from django.http import HttpResponse, HttpResponseRedirect
  from django.urls import reverse
  
  from .models import *
  from .forms import *
  
  
  class IndexView(generic.ListView):
      template_name = 'tasks/index.html'
      form_class = AddGroupForm
      model = Group
  
      def get_queryset(self):
          return self.groups.order_by('title')
  
      def get(self, request):
          self.groups = Group.objects.all().order_by('title')
          form = self.form_class(request.GET)
          return render(request, self.template_name, {'form': form, 'groups': self.groups})
  
      def post(self, request):
          form = self.form_class(request.POST)
          if form.is_valid():
              form.save()
              return redirect('/')
  
          return render(request, self.template_name, {'form': form, 'groups': self.groups})
  
  
  class GroupView(generic.ListView):
      template_name = 'tasks/group.html'
      form_class = AddTaskForm
      model = Task
  
      def get_queryset(self):
          return self.tasks.order_by('-completed', 'title')
  
      def get(self, request, pk):
          self.group_id = pk
          self.tasks = Group.objects.get(pk=pk).task_set.all()
          form = self.form_class(request.GET, pk)
          return render(request, self.template_name, {'form': form, 'tasks': self.tasks})
  
      def post(self, request, pk):
          form = self.form_class(request.POST)
          if form.is_valid():
              form = form.save(commit=False)
          form.group_id = pk
          form.save()
          return HttpResponseRedirect(reverse('tasks:group', args=[pk]))
  </code></pre>
  <pre><code>urls.py
  from django.urls import path
  
  from . import views
  
  
  app_name = 'tasks'
  
  urlpatterns = [
      path('', views.IndexView.as_view(), name = 'index'),
      path('&lt;str:pk&gt;/', views.GroupView.as_view(), name = 'group'),
  ]
  
  </code></pre>