-
-
Save AnyiLloyd/a963e9e3f52aa8f46fd7ef9a6ec0dddb to your computer and use it in GitHub Desktop.
SchApp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% extends 'student/base.html' %} | |
{% block title %}Detail page{% endblock %} | |
{% block body %} | |
<div class="container subject-container"> | |
<div class="row"> | |
<!-- profile photo--> | |
<div class="col-sm-4 col-md-3"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1> | |
</div> | |
<div class="panel-body"> | |
<a href="{% url 'student:detail' profile.id %}"> | |
{% if profile.photo %} | |
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px"> | |
{% else %} | |
<p class="small">No image to display</p> | |
{% endif %} | |
</a> | |
</div> | |
</div> | |
</div> | |
<!-- Subject Add--> | |
<div class="col-sm-12 col-md-7"> | |
<div class="panel panel-success"> | |
<div class="panel-heading"> | |
<h1 class="panel-title">Add Subject</h1> | |
</div> | |
<div class="panel-body"> | |
<h3>Add Subject</h3> | |
{% if error_message %} | |
<p><strong>{{ error_message }}</strong></p> | |
{% endif %} | |
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data"> | |
{% csrf_token %} | |
<input type="hidden" name="profile" value="{{ profile }}"> | |
{% include 'student/form-profile-temp.html' %} | |
<div class="form-group"> | |
<div class="col-sm-offset-2 col-sm-10"> | |
<button type="submit" class="btn btn-success">Submit</button> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'student/base.html' %} | |
{% block title %}Detail page{% endblock %} | |
{% block body %} | |
<div class="container profile-container"> | |
<div class="row"> | |
<!--profile Infor--> | |
<div class="col-sm-4 col-md-3"> | |
<div class="panel panel-success"> | |
<div class="panel-heading"> | |
<h4 class="panel-title">{{ profile.lastName }} {{ profile.firstName }}</h4> | |
</div> | |
<div class="panel-body"> | |
<a href="{% url 'student:detail' profile.id %}"> | |
{% if profile.photo %} | |
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px"> | |
{% else %} | |
<p class="small">No image to display</p> | |
{% endif %} | |
</a> | |
</div> | |
<div class="panel-footer"> | |
School ID:<small><i>{{ profile.stud_id }}</i></small><br>DoB: <small><i>{{ profile.dob }}</i></small><br> | |
Comment: <i>{{ profile.Comment }}</i> | |
</div> | |
</div> | |
</div> | |
<!-- Right Detailed student info--> | |
<div class="col-sm-8 col-md-9"> | |
<div class="btn btn-group nav nav-pills" role="group" arial-label="..."> | |
<a href="{% url 'student:detail' profile.id %}" type="button" class="btn btn-default btn-sm"> | |
<span class="glyphicon glyphicon-eye-open"> View All Record</span> </a> | |
<a href="{% url 'student:add_subj' profile.id %}" type="button" class="btn btn-success btn-sm"> | |
<span class="glyphicon glyphicon-plus"> Add Subject</span></a> | |
<a href="#"type="button" class="btn btn-default btn-sm"> | |
<span class="glyphicon glyphicon-pencil"> Make Comment</span></a> | |
</div> | |
<div class="panel panel-success"> | |
<div class="panel-heading"> | |
<h4 class="panel-title">Academic Performance</h4> | |
</div> | |
<div class="panel-body"> | |
{% if error_message %} | |
<p><strong>{{ error_message }}</strong></p> | |
{% endif %} | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Subject</th> | |
<th>Score</th> | |
<th>Grade</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for course in profile.course_set.all %} | |
<tr> | |
<td>{{ course.subject }}</td> | |
<td>{{ course.score }}</td> | |
<td>{{ course.grade }}</td> | |
</tr> | |
{% endfor %} | |
</tbody> | |
</table> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from datetime import date | |
from django.core.urlresolvers import reverse | |
from django.shortcuts import redirect | |
class Profile(models.Model): | |
firstName = models.CharField(max_length=30) | |
middleName = models.CharField(max_length=30) | |
lastName = models.CharField(max_length=30) | |
dob = models.DateField(blank=True, null=True) | |
stud_id = models.CharField(max_length=5000) | |
gender = models.CharField(max_length=10) | |
parentsName =models.CharField(max_length=30) | |
address = models.CharField(max_length=250) | |
lga = models.CharField(max_length=250) | |
Religion = models.CharField(max_length=50) | |
email = models.EmailField(max_length=70, null=True, blank=True, unique=True) | |
phone = models.CharField(max_length=11, unique=True) | |
photo = models.FileField() | |
Comment = models.CharField(max_length=250) | |
def get_absolute_url(self): | |
return reverse('student:detail', kwargs={'pk': self.pk}) | |
def __str__(self): | |
return self.firstName | |
class Course(models.Model): | |
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True) | |
subject = models.CharField(max_length=20) | |
score = models.CharField(max_length=20) | |
grade = models.CharField(max_length=20) | |
def get_absolute_url(self,): | |
return reverse('student:detail', kwargs={'pk': self.pk}) | |
def __str__(self): | |
return self.subject | |
class Result(models.Model): | |
profile = models.ForeignKey(Profile, on_delete=models.CASCADE,) | |
results = models.CharField(max_length=20) | |
term = models.CharField(max_length=20) | |
def __str__(self): | |
return self.results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from . import views | |
urlpatterns = [ | |
#index url | |
url(r'^$', views.IndexView.as_view(), name='index'), | |
url(r'^signup/$', views.UserFormView.as_view(), name='signup'), | |
#details | |
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'), | |
#profile/add | |
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'), | |
#course/add | |
url(r'^add_subj/(?P<pk>[0-9]+)/$', views.CourseCreate.as_view(), name='add_subj'), | |
#profile/pk for update | |
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'), | |
#profile/pk for deleting | |
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views import generic | |
from django.views.generic import View | |
from django.views.generic.edit import CreateView, UpdateView, DeleteView | |
from django.core.urlresolvers import reverse_lazy, reverse | |
from django.shortcuts import render, redirect | |
from django.contrib.auth import authenticate, login | |
from .models import Profile, Course | |
from .forms import UserForm | |
#Index view | |
class IndexView(generic.ListView): | |
template_name = 'student/index.html' | |
context_object_name = 'all_profile' | |
def get_queryset(self): | |
return Profile.objects.all() | |
#Detail view | |
class DetailView(generic.DetailView): | |
model = Profile | |
template_name = 'student/detail.html' | |
#Add student section | |
class ProfileCreate(generic.CreateView): | |
model = Profile | |
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address', | |
'lga', 'Religion', 'email', 'phone', 'photo'] | |
#Add Subject section | |
class CourseCreate(generic.CreateView): | |
model = Course | |
fields = ['subject', 'score', 'grade'] | |
def post(self, request, *args, **kwargs): | |
form = Course(request.POST) | |
course = form.save(commit=False) | |
course.subject = 'subject' | |
course.score = 'score' | |
course.grade = 'grade' | |
course.save() | |
#Update Student Section | |
class ProfileUpdate(UpdateView): | |
model = Profile | |
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address', | |
'lga', 'Religion', 'email', 'phone', 'photo'] | |
#Delete Student Section | |
class ProfileDelete(DeleteView): | |
model = Profile | |
success_url = reverse_lazy('student:index') | |
#User signup form | |
class UserFormView(View): | |
form_class = UserForm | |
template_name = 'student/signup_form.html' | |
#Displays a blank form to new user | |
def get(self, request): | |
form = self.form_class(None) | |
render(request, self.template_name, {'form': form}) | |
#form processing | |
def post(self, request): | |
form = self.form_class(request.POST) | |
if form.is_valid(): | |
user = form.save(commit=False) | |
#Normalized data(clean formatted data) | |
username = form.cleaned_data['username'] | |
password = form.cleaned_data['password'] | |
#change user password | |
user.set_password(password) | |
user.save() | |
#Returning users with correct crdentials | |
user = authenticate(username=username, password=password) | |
if user is not None: | |
if user.is_active: | |
login(request, user) | |
return redirect('student/index') | |
return render(request, self.template_name, {'form': form}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am trying to develop an app for student management. Every thing seems to be working fine. but am receiving an errors at some point. If i open the list view it shows all the student, if i click a student photo it will open a detail view of that student for me, then if i click add button inside the view it will show me (NoReverseMatch at /add_subj/3/
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P[0-9]+)/$'] ). I want to be able to add subject to a particular id. Please need some help, am new in django.