dimanche 22 avril 2018

How to create new cloumns from existing columns in django sqlite models.py files?

I am creating a simple result processing system using django. I made this class:

class Course(models.Model):
    Course_Code = models.CharField(max_length=50,unique=True,primary_key = True)
    Course_Name = models.CharField(max_length=50)
    Dept = models.CharField(max_length=50)
    Credit_Lecture = models.IntegerField()
    Credit_Tutorial = models.IntegerField()
    Credit_Practical = models.IntegerField()
    Max_Marks_MidTerm = models.IntegerField()
    Max_Marks_Theory = models.IntegerField()
    Max_Marks_Pr = models.IntegerField()

Now I want to make a new column that stores the total credit value of a course i.e. :

Credit_Total = Credit_Lecture + Credit_Tutorial + Credit_Practical

How should I do so? I found the following possibilities but failed:

Total_Credit =Credit_Lec + Credit_Tut + Credit_Pr

Total_credit = SELECT CAST(Credit_lec AS VARCHAR(255)) AS credit_lec FROM Course;




Aucun commentaire:

Enregistrer un commentaire