Clean: cleaned homepage/views.py

New Feature: edited createUser_form, views, and models of homepage app to allow users to add their department in user creation
parent 6d574d1c
# Generated by Django 3.2.12 on 2022-05-25 19:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0032_alter_widgetuser_profile_pic'),
]
operations = [
migrations.AlterField(
model_name='department',
name='dept_name',
field=models.CharField(default='none', max_length=50),
),
migrations.AlterField(
model_name='department',
name='home_unit',
field=models.CharField(default='none', max_length=50),
),
migrations.AlterField(
model_name='widgetuser',
name='profile_pic',
field=models.ImageField(default='faceless.png', upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-25 19:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0033_auto_20220525_2249'),
]
operations = [
migrations.AlterField(
model_name='department',
name='dept_name',
field=models.CharField(default='none', max_length=50, null=True),
),
migrations.AlterField(
model_name='department',
name='home_unit',
field=models.CharField(default='none', max_length=50, null=True),
),
]
...@@ -16,8 +16,8 @@ class WidgetUser(models.Model): ...@@ -16,8 +16,8 @@ class WidgetUser(models.Model):
last_name = models.CharField(max_length=50, default='last_name') last_name = models.CharField(max_length=50, default='last_name')
id_num = models.CharField(max_length=7, default='1234567') id_num = models.CharField(max_length=7, default='1234567')
email = models.CharField(max_length=50, default='someemail@gmail.com') email = models.CharField(max_length=50, default='someemail@gmail.com')
profile_pic = models.ImageField(default="faceless.png", null=True, blank=True) profile_pic = models.ImageField(default="faceless.png")
department = models.ForeignKey(Department, on_delete=models.CASCADE, null=False, blank=False, default="1") department = models.ForeignKey(Department, on_delete=models.CASCADE, default="1")
def __str__(self): def __str__(self):
return self.last_name return self.last_name
\ No newline at end of file
...@@ -8,7 +8,20 @@ ...@@ -8,7 +8,20 @@
<h3> Enter Middle Name: </h3> <input type="text" name="Middle name"> <h3> Enter Middle Name: </h3> <input type="text" name="Middle name">
<h3> Enter ID Number: </h3> <input type="text" name="ID Number"> <h3> Enter ID Number: </h3> <input type="text" name="ID Number">
<h3> Enter Email address: </h3> <input type="text" name="Email address"> <h3> Enter Email address: </h3> <input type="text" name="Email address">
<!-- will change department name -->
<input type="Submit"> <br>
<br>
<select class="custom-select mb-4" name="newDepartment">
<option selected> Select your department </option>
{% for department in Department %}
<option value="{{ department.pk }}"> {{ department.dept_name }} </option>
{% endfor %}
</select>
<br>
<br>
<button class="button" type="submit"> Save New User </button>
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
from tkinter import Widget
from .models import Department from .models import Department
from .models import WidgetUser from .models import WidgetUser
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
...@@ -12,7 +11,11 @@ def index(request): ...@@ -12,7 +11,11 @@ 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):
return render(request, "homepage/createUser_form.html") department = Department.objects.all()
context = {
"Department": department
}
return render(request, "homepage/createUser_form.html", context)
def newUser(request): def newUser(request):
if request.method == "POST": if request.method == "POST":
...@@ -21,14 +24,11 @@ def newUser(request): ...@@ -21,14 +24,11 @@ def newUser(request):
last_name = request.POST.get("Last name") last_name = request.POST.get("Last name")
id_num = request.POST.get("ID Number") id_num = request.POST.get("ID Number")
email = request.POST.get("Email address") email = request.POST.get("Email address")
# will add department 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) 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 HttpResponse("User Added")
def detail(request, widgetuser_id): def detail(request, widgetuser_id):
# widgetUser = WidgetUser.objects.get(pk=widgetuser_id)
# if not widgetUser.exists():
# raise Http404("User does not exist!")
try: try:
widgetUser = WidgetUser.objects.get(pk=widgetuser_id) widgetUser = WidgetUser.objects.get(pk=widgetuser_id)
except WidgetUser.DoesNotExist: except WidgetUser.DoesNotExist:
......
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