Django dynamic table with some bootstrap-7
MODEL PART
class Info(models.Model):
name=models.CharField(max_length=200)
s_id=models.CharField(max_length=100,unique=True)
email=models.EmailField(max_length=200)
date=models.DateTimeField(auto_now_add=True)
def __str__(self):
return str(self.s_id)
############################VIEW PART########################################
from django.shortcuts import render
from django.http import HttpResponse
from .models import Topic,Webpage,Accessrecord,Info
# Create your views here.
def newtable(request):
studentlist=Info.objects.order_by('s_id')
dicto={'students':studentlist}
return render(request,"firsr_app/newtable.html",dicto)
###################################ADMIN PART####################################
from django.contrib import admin
# Register your models here.
from .models import Topic,Webpage,Accessrecord,Info
admin.site.register(Topic)
admin.site.register(Webpage)
admin.site.register(Accessrecord)
admin.site.register(Info)
########################### HTML PART ###############################################
{%load static%}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{%static 'css\bootstrap.min.css' %}">
<title>table</title>
</head>
<body>
<br>
<div class="container table-responsive-sm">
<h1 class="text-center font-italic text-primary font-weight-bolder">Active Students Table </h1>
<table class=" mt-3 table table-bordered table-hover table-active ">
<thead>
<tr class=" text-center bg-dark text-white " >
<th colspan="4" class="font-weight-bolder"><h3>Student Table</h3> </th>
</tr>
<tr >
<td class="text-center font-weight-bolder table-secondary">NAME</td>
<td class="text-center font-weight-bolder table-secondary">ID</td>
<td class="text-center font-weight-bolder table-secondary">EMAIL</td>
<td class="text-center font-weight-bolder table-secondary">DATE/TIME</td>
</tr>
</thead>
<tbody>
{%if students %}
{%for i in students %}
<tr>
<td class="text-center">{{i.name}}</td>
<td class="text-center">{{i.s_id}}</td>
<td class="text-center">{{i.email}}</td>
<td class="text-center">{{i.date}}</td>
</tr>
{%endfor%}
{%endif%}
</tbody>
</table>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>
Comments
Post a Comment