django framework uses two template instantiation

Foreword

This article describes the django framework using the template method, a detailed analysis of the relevant tips Django framework template and Handling Precautions combine two specific examples of the form, a friend in need can refer to.

I'm here to do a centralized shared, like if there is content, legacies, if you encounter any problems, please give me a message below can!

This paper describes examples of using templates django framework. Share to you for your reference, as follows:

models.py:

from django.db import models
# Create your models here.
class Book(models.Model):
  title=models.CharField(max_length=32,unique=True)
  price=models.DecimalField(max_digits=8,decimal_places=2,null=True)
  pub_date=models.DateField()
  publish=models.CharField(max_length=32)
  is_pub=models.BooleanField(default=True)
  authors=models.ManyToManyField(to="Author")
class AuthorDetail(models.Model):
  gf=models.CharField(max_length=32)
  tel=models.CharField(max_length=32)
class Author(models.Model):
  name=models.CharField(max_length=32)
  age=models.IntegerField()
  # 与AuthorDetail建立一对一的关系
  Models.ForeignKey AD = # (to = "AuthorDetail", to_field = "the above mentioned id", on_delete = models.CASCADE, UNIQUE = True) 
  #OneToOneField represents the creation of one relationship. on_delete = models.CASCADE expressed cascading deletes. Assume that a table record Delete a, b will also delete the corresponding table of records 
  ad = models.OneToOneField (to = "AuthorDetail ", to_field = "id", on_delete = models.CASCADE,)

  

Guess you like

Origin www.cnblogs.com/sq1995liu/p/12132988.html