Click here to Skip to main content
15,567,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
Python
from Django.DB import models
from Django.conf import settings
from Django. utils import timezone
import enum

# Create your models here.

class BookOrCourse(models.Model) :
    # fields
    # using tuples and enums
    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)#

    # methods


    def __str__(self):
        return self.title


but I do not know how to get the name of my items such as
Python
Advanced
or
Python
Course
.When I add a record to my SQL table it just prints the numbers. It is a part of my HTML file:
HTML
{% 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
Python
.name
to end of
Python
level
and
Python
rec_type
but in this time it prints nothing.I will be gratefull for your help .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900