Migrating manual form to forms.py

I am very new to Django and can use some help. I’ve created a manual form in a html file, (my custnames,html file), and it works fine. It contains a database query “select” section and an “onchange submit form” entry. For the life of me I cannot move it to my forms.py file and still have it work. The functionality is for the user to select a customer from a drop-down list and as soon as that is done, a GET is sent. This works because I can see the “nameocust=nn” entry in the URL. I would appreciate any suggestions that anyone can forward to me.

from django.db import models

This will hold the team members

class CustTeamMembers(models.Model):
member_first_name = models.CharField(max_length = 100)
member_last_name = models.CharField(max_length = 100)
member_email = models.EmailField(unique=True)
member_phone = models.CharField(max_length = 25, blank=True)

class Meta(object):
    ordering = ['member_last_name']

def __str__(self):
    return self.member_last_name

This will hold the customer name

class CustTeamName(models.Model):
cust_name = models.CharField(max_length = 100)
cust_members = models.ManyToManyField(CustTeamMembers, blank=True)
cust_meet = models.CharField(max_length = 40, blank=True)
cust_status = models.TextField(blank=True)

def __str__(self):
    return self.cust_name

def get_members(self):
    return ", ".join([str(p) for p in self.cust_members.all()])

{% extends ‘custdat/base.html’ %}
{% block ‘body’ %}

<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #238a44">
    <div class="container">
        <a class="navbar-brand" href="{% url 'home' %}">The Home Button</a>

<center><h1>CUSTOMER TEAM PAGE</h1></center>

    <form action="{% url 'custnames' %}" method="get">
        {% csrf_token %}

            <h2>Choose A TISS Customer Team To Review</h2>
            <select id="nameocust" name="nameocust" onchange="this.form.submit();">

            <option value="0" selected disabled>Select Team</option>
            {% for custname in custnamesall %}
                <option value="{{ custname.id }}">{{ custname.cust_name }}</option>
            {% endfor %}


{% endblock %}

from django.shortcuts import render

#from .forms import CustForm
from .models import CustTeamMembers, CustTeamName

Create your views here.

def home(request):
return render(request, ‘custdat/home.html’)

def custnames(request):
custnamesall = CustTeamName.objects.all()
return render(request, ‘custdat/custnames.html’, { ‘custnamesall’: custnamesall,})

forms.py (As it is now)
from django import forms

class CustForm(forms.Form):
cust_name = forms.CharField(label=‘Customer Name’, max_length=100)
cust_status = forms.CharField(label=‘Customer Status’)

I don’t suggest trying to start from an HTML form and retrofitting it to Django. I believe you’ll really find it easier to work in the other direction - build your form in Django first, taking advantage of all the features provided by the framework, and then styling the form as necessary or desired after you have the form working.

For some background information, start with the Working With Forms docs, and follow that through to the other related pages.

I would also suggest starting with a simple form containing just one or two character fields until you start to “get” how forms work here.

Also, if you haven’t yet done so, I strongly suggest you work your way through either the official Django Tutorial or the Django Girls tutorial. They’ll help you learn and understand what’s going on here.

As a side note, when you post code snippets, please insert them between lines containing only 3 backticks - ```. (Make sure you use the backtick - ` and not the apostrophe - '.) That means you would have one line with the 3 backticks, your code, and then one more line with just the 3 backticks. That allows this forum software to format your code nicely:

# The line above this is just ```
def function(parm):
    return parm
# The line after this is just ```

Please edit your post to put the backticks before and after the code.