所以,我想创建一个 Django 培训计划。我的数据库模型看起来
models.py
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
class Coach(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name="Пользователь", related_name="coach")
name = models.CharField(max_length=200)
phone = models.CharField(max_length=200)
desc = models.CharField(max_length=500)
avatar = models.ImageField(upload_to="coach_avatars/", blank=True)
def __str__(self):
return self.user.get_full_name()
class TypeOfTraining(models.Model):
coach = models.ForeignKey(Coach, on_delete=models.CASCADE, related_name="training_type")
name = models.CharField(max_length=100)
desc = models.CharField(max_length=500)
price = models.FloatField(default=0)
def __str__(self):
return self.name
class TrainingSchedule(models.Model):
coach = models.ForeignKey(Coach, on_delete=models.CASCADE)
training_type = models.ForeignKey(TypeOfTraining, on_delete=models.CASCADE)
start_at = models.DateTimeField()
def __str__(self):
return str(self.id)
如何以看起来像图像的 html 形式显示数据库中的数据? 示例:HTML 页面上的日程安排看起来如何
我已经做了HTML模板。但我不知道如何在模板中显示数据库中的数据。
PS 抱歉我的英语。
潇湘沐
相关分类