Many-table structure design:

Models django.db Import from 
# the Create your Models here Wallpaper.
class Publisher (models.Model):
name = models.CharField (MAX_LENGTH = 32)
DEF __str __ (Self):
return the self.name

class Book (models.Model):
name = models.CharField (MAX_LENGTH = 32)
Pub = models.ForeignKey (Publisher, on_delete = models.CASCADE,)
DEF __str __ (Self):
return the self.name

"" "
on_delete version 2.0 is required after the
on_delete =
models.CASCADE cascade delete
PROTECT protecting
the sET (1)
set_default set as the default value for a certain value
SET_NULL set to null
DO_NOTHING change anything
. "" "

the Author class (models.Model):
name = models.CharField (MAX_LENGTH = 32)
Books = models.ManyToManyField ( 'Book') # does not generate a column of a table generated

# class AuthorBook (models.Model):
# = author models.ForeignKey (Author)
# = models.ForeignKey Book (Book)

Guess you like

Origin www.cnblogs.com/zhang-da/p/12050878.html