Hello.
I am learning Django and python and I'm just a beginner. In models.py I have one class and I used tuples and enums in it. Here is the code :
from Django.DB import models
from Django.conf import settings
from Django. utils import timezone
import enum
class BookOrCourse(models.Model) :
COURSE = 1
BOOK = 2
RECOMMENDED_TYPES = (
(COURSE , 'Course'),
(BOOK , 'Book'),
)
ADVANCED = 3
INTERMEDIATE = 4
INCIPIANT = 5
Level_Types = (
(ADVANCED , 'Advanced'),
(INTERMEDIATE , 'Intermediate'),
(INCIPIANT , 'Incipiante'),
)
title = models.CharField(max_length=255 , null=True , blank = True)
producername = models.CharField(max_length=255 , null=True , blank = True)
level = models.PositiveSmallIntegerField(null = True,choices=Level_Types)
rec_type = models.PositiveSmallIntegerField(null = True,choices=RECOMMENDED_TYPES)
def __str__(self):
return self.title
but I do not know how to get the name of my items such as
Advanced
or
Course
.When I add a record to my SQL table it just prints the numbers. It is a part of my HTML file:
{% for i in key %}
<tr>
<td>{{i.title}}</td>
<td>{{i.producername}}</td>
<td>{{i.level}}</td>
<td>{{i.rec_type}}</td>
</tr>
{% endfor %}
What I have tried:
I also tried to add
.name
to end of
level
and
rec_type
but in this time it prints nothing.I will be gratefull for your help .