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
BookCountmodel is required you could use a listener for thepost_savesignal along the lines of this:If your models are really this simple, you may want to drop the
BookCountmodel and add acountfield to yourBookmodel 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 theOneToOneFieldoption (the wording is specific to theUsermodel, but it applies here, too):