models:
class Book(models.Model):
name = models.Char()
class BookCount(models.Model):
book = OneToOneField(Book)
count = SmallIntegerField(default=0)
views:
class BookCreate(CreateView):
model = Application
The question is, after create Book, I want insert a record to BookCount. Any ideas?
If your
BookCount
model is required you could use a listener for thepost_save
signal along the lines of this:If your models are really this simple, you may want to drop the
BookCount
model and add acount
field to yourBook
model instead to reduce the complexity and overhead here. See the docs on extending the user model for a short overview of why it might be better to avoid theOneToOneField
option (the wording is specific to theUser
model, but it applies here, too):