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 import forms
from django.forms import ModelForm
from homepage.models import WidgetUser from homepage.models import WidgetUser, Department
class IndexCardForm(forms.Form): class CreateUserForm(ModelForm, forms.Form):
name = forms.CharField(label='Full Name', max_length=100) class Meta:
section = forms.CharField(label='CSCI40 Section', max_length=5) model = WidgetUser
age = forms.IntegerField(label='Current Age') fields = ["last_name", "first_name", "middle_name", "id_num", "email"]
\ No newline at end of file
departments = forms.ModelChoiceField(
label='Department',
queryset=Department.objects.all(),
initial=Department.objects.first()
)
\ No newline at end of file
{% extends "homepage/base.html" %} {% extends "homepage/base.html" %}
{% block content %} {% block content %}
<form action="newUser/" method="POST"> <h1>Create User:</h1>
<form method="POST" action="{% url 'homepage:newUser' %}">
{% csrf_token %} {% csrf_token %}
<!-- {{ createUserForm.as_p }} -->
<h3> Enter Last Name: </h3> <input type="text" name="Last name"> <h3> Enter Last Name: </h3> <input type="text" name="Last name">
<h3> Enter First Name: </h3> <input type="text" name="First name"> <h3> Enter First Name: </h3> <input type="text" name="First name">
<h3> Enter Middle Name: </h3> <input type="text" name="Middle name"> <h3> Enter Middle Name: </h3> <input type="text" name="Middle name">
...@@ -23,5 +27,11 @@ ...@@ -23,5 +27,11 @@
<br> <br>
<button class="button" type="submit"> Save New User </button> <button class="button" type="submit"> Save New User </button>
<br>
<br>
<a href="{% url 'homepage:index' %}"> Return to Homepage </a>
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
from .models import Department from homepage.forms import CreateUserForm
from .models import WidgetUser from .models import WidgetUser, Department
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import render from django.shortcuts import redirect, render
def index(request): def index(request):
widgetUser = WidgetUser.objects.order_by("last_name") widgetUser = WidgetUser.objects.order_by("last_name")
...@@ -11,9 +11,20 @@ def index(request): ...@@ -11,9 +11,20 @@ def index(request):
return render(request, "homepage/widgetusers_orderedlist.html", context) return render(request, "homepage/widgetusers_orderedlist.html", context)
def createUser(request): 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() department = Department.objects.all()
context = { context = {
"Department": department "Department": department,
# "createUserForm" : createUserForm
} }
return render(request, "homepage/createUser_form.html", context) return render(request, "homepage/createUser_form.html", context)
...@@ -26,7 +37,7 @@ def newUser(request): ...@@ -26,7 +37,7 @@ def newUser(request):
email = request.POST.get("Email address") email = request.POST.get("Email address")
dept_Value = request.POST.get("newDepartment") 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) 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): def detail(request, widgetuser_id):
try: try:
......
...@@ -10,6 +10,10 @@ h3 { ...@@ -10,6 +10,10 @@ h3 {
color: palevioletred; color: palevioletred;
font-weight: bold; font-weight: bold;
} }
p {
color: palevioletred;
font-weight: bold;
}
ol { ol {
color: wheat; color: wheat;
font-weight: bold; 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