title: Generic view for different models in django
body: <p>To summarize the project, I am working on a website that categorizes electronic devices. Each electronic device has a category (Phone, Tablet, Computer, etc...), a manufacturer (Apple, Samsung, Dell, etc...) and the device itself (iPhone 6, iPhone X, Samsung S21, etc...).</p>
  <p>I have a single template for the 3 different models (Category, Manufacture, Device) and I am looking to simplify the views which are currently just a copy and paste.</p>
  <p>Here is the current code:</p>
  <pre><code>@login_required(login_url=&quot;/login/&quot;)
  def show_category(request):
      groups = Category.objects.all()
      return render(request, &quot;groups/group.html&quot;, {'group': 'Category', 'groups': groups})
  
  
  @login_required(login_url=&quot;/login/&quot;)
  def show_manufacturer(request):
      groups = Manufacturer.objects.all()
      return render(request, &quot;groups/group.html&quot;, {'group': 'Manufacturer', 'groups': groups})
  
  
  @login_required(login_url=&quot;/login/&quot;)
  def show_device(request):
      groups = Device.objects.all()
      return render(request, &quot;groups/group.html&quot;, {'group': 'Device', 'groups': groups})
  </code></pre>
  <p>Additionally, I have some POST functions which are also copy pastes of the same function for the different models to the same template.</p>
  <p>I have been able to find examples where multiple models are used at the same time for one template, but I cannot for the life of me seem to find an example of using different models for the same template.</p>
  <p>Can someone link me to an example or the docs that explains how to accomplish this ?</p>
  <p>I feel like I have missed something from reading the docs, or maybe I simply don't quite grasp the whole models, views, templates way of doing it in Django as I feel this is supposed to be the whole concept of Django, simplifying the code in such ways using powerful views and templates.</p>
  <p>Thank you !</p>