New Feature: edited homepage/forms.py for use if ever

parent dcfbdfaa
from multiprocessing.sharedctypes import Value
from unicodedata import name
from django import forms
from django.forms import ModelForm
from homepage.models import WidgetUser
from homepage.models import WidgetUser, Department
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
class CreateUserForm(ModelForm, forms.Form):
class Meta:
model = WidgetUser
fields = ["last_name", "first_name", "middle_name", "id_num", "email"]
departments = forms.ModelChoiceField(
label='Department',
queryset=Department.objects.all(),
initial=Department.objects.first()
)
\ No newline at end of file
{% extends "homepage/base.html" %}
{% block content %}
<form action="newUser/" method="POST">
<h1>Create User:</h1>
<form method="POST" action="{% url 'homepage:newUser' %}">
{% csrf_token %}
<!-- {{ createUserForm.as_p }} -->
<h3> Enter Last Name: </h3> <input type="text" name="Last name">
<h3> Enter First Name: </h3> <input type="text" name="First name">
<h3> Enter Middle Name: </h3> <input type="text" name="Middle name">
......@@ -23,5 +27,11 @@
<br>
<button class="button" type="submit"> Save New User </button>
<br>
<br>
<a href="{% url 'homepage:index' %}"> Return to Homepage </a>
</form>
{% endblock %}
\ No newline at end of file
from .models import Department
from .models import WidgetUser
from homepage.forms import CreateUserForm
from .models import WidgetUser, Department
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import redirect, render
def index(request):
widgetUser = WidgetUser.objects.order_by("last_name")
......@@ -11,9 +11,20 @@ def index(request):
return render(request, "homepage/widgetusers_orderedlist.html", context)
def createUser(request):
# if request.method == "POST":
# createUserForm = CreateUserForm(request.POST)
# if createUserForm.is_valid():
# newWidgetUser = createUserForm.save()
# newWidgetUser.department_id = Department.objects.get(request.POST['Department'].pk)
# newWidgetUser.save()
# return redirect("homepage:createUser")
# else:
# createUserForm = CreateUserForm()
department = Department.objects.all()
context = {
"Department": department
"Department": department,
# "createUserForm" : createUserForm
}
return render(request, "homepage/createUser_form.html", context)
......@@ -26,7 +37,7 @@ def newUser(request):
email = request.POST.get("Email address")
dept_Value = request.POST.get("newDepartment")
widgetUser = WidgetUser.objects.create(first_name=first_name, middle_name=middle_name, last_name=last_name, id_num=id_num, email=email, department_id=dept_Value)
return HttpResponse("User Added")
return redirect("homepage:createUser")
def detail(request, widgetuser_id):
try:
......
......@@ -10,6 +10,10 @@ h3 {
color: palevioletred;
font-weight: bold;
}
p {
color: palevioletred;
font-weight: bold;
}
ol {
color: wheat;
font-weight: bold;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment