quart-2

 


from django.shortcuts import render
from django.views import View
from student.models.studentmodel import Studentmodel


class StudentView(View):
    def get(selfrequest, *args, **kwargs):
        student_object=Studentmodel.getmethod()
        # student_object=Studentmodel.objects.first()
        # student_object=Studentmodel.objects.order_by('name').last()
        # student_object=Studentmodel.objects.latest('pass_date')
        # student_object = Studentmodel.objects.earliest('pass_date')

        print(student_object)
        print()
        print(student_object)
 
        student_dictionary={
            "student_data_key":student_object
        }
        return render(request,'student/studentml.html',student_dictionary)


=======================================================================================

from django.db import models

# Create your models here.


class Studentmodel(models.Model):
    name=models.CharField(max_length=50)
    roll=models.IntegerField(unique=True,null=False,verbose_name='Roll Number',help_text='This is roll')
    city=models.CharField(max_length=50)
    pass_date=models.DateTimeField(auto_now_add=True)




    @staticmethod
    def getmethod():
        return  Studentmodel.objects.get(id=1#get is not iterable by for loop in template

    

=========================================================================================


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Data</title>
</head>
<body>
    
    
    <table border='2'>
    <tr>
    <th>Name</th>
    <th>Roll</th>
    <th>City</th>
    <th>Pass Date</th>
    </tr>
     {% comment %} {% for i in student_data_key %} {% endcomment %}
     <tr>
     <td>{{student_data_key.name}}</td>
     <td>{{student_data_key.roll}}</td>
     <td>{{student_data_key.city}}</td>
     <td>{{student_data_key.pass_date}}</td>
     </tr>

     {% comment %} {% endfor %} {% endcomment %}

    </table>
    
    
</body>
</html>

Comments

Popular posts from this blog

D WEB LINK