Commit bbb1efd5 authored by Bryan Carlo Guanlao's avatar Bryan Carlo Guanlao
parents e1e5857b 3a15f67f
from django.db import models from django.db import models
from django.urls import reverse
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=30) dept_name = models.CharField(max_length=30)
...@@ -20,3 +22,6 @@ class WidgetUser(models.Model): ...@@ -20,3 +22,6 @@ class WidgetUser(models.Model):
def __str__(self): def __str__(self):
return f"{self.first_name} {self.middle_name} {self.last_name}" return f"{self.first_name} {self.middle_name} {self.last_name}"
def get_absolute_url(self):
return reverse('homepage:widgetuser-list')
{% block content %} {% block content %}
<li>
<a href="{% url 'homepage:widgetuser-list' %}">Homepage</a>
</li>
<ul> <ul>
<li>Complete Name: {{widgetuser.last_name}}, {{widgetuser.first_name}} {{widgetuser.middle_name}}</li> <li>Complete Name: {{widgetuser.last_name}}, {{widgetuser.first_name}} {{widgetuser.middle_name}}</li>
<li>{{widgetuser.id_num}}</li> <li>{{widgetuser.id_num}}</li>
......
{% block content %}
<li>
<a href="{% url 'homepage:widgetuser-list' %}">Homepage</a>
</li>
<h1>Add Widget User</h1>
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Save New User">
</form>
{% endblock content %}
...@@ -10,5 +10,8 @@ ...@@ -10,5 +10,8 @@
</a> </a>
</body> </body>
{% endfor %} {% endfor %}
<a href="{% url 'homepage:widgetuser-create' %}">
<br>Add Widget User
</a>
</ul> </ul>
{% endblock content%} {% endblock content%}
from django.urls import path from django.urls import path
from .views import WidgetUserListView, WidgetUserDetailView from .views import WidgetUserListView, WidgetUserDetailView, WidgetUserCreateView
urlpatterns = [ urlpatterns = [
path('', WidgetUserListView.as_view(), name='widgetuser-list'), path('', WidgetUserListView.as_view(), name='widgetuser-list'),
path('users/<str:id_num>/details/', WidgetUserDetailView.as_view(), name='widgetuser-detail') path('users/<str:id_num>/details/', WidgetUserDetailView.as_view(), name='widgetuser-detail'),
path('users/add/', WidgetUserCreateView.as_view(), name='widgetuser-create')
] ]
app_name = 'homepage' app_name = 'homepage'
from django.shortcuts import render from django.http import HttpResponse
from django.shortcuts import render, redirect
from .models import Department, WidgetUser from .models import Department, WidgetUser
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
class WidgetUserListView(ListView): class WidgetUserListView(ListView):
model = WidgetUser model = WidgetUser
...@@ -10,3 +13,7 @@ class WidgetUserDetailView(DetailView): ...@@ -10,3 +13,7 @@ class WidgetUserDetailView(DetailView):
model = WidgetUser model = WidgetUser
def get_object(self, queryset=None): def get_object(self, queryset=None):
return WidgetUser.objects.get(id_num=self.kwargs.get("id_num")) return WidgetUser.objects.get(id_num=self.kwargs.get("id_num"))
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
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