I
I
Intelide2017-02-10 13:52:20
Django
Intelide, 2017-02-10 13:52:20

How to add a value to the base to the associated object?

Hello.
There are models

class Autor(models.Model):
    first_name = models.CharField(max_length=100)

class Books(models.Model):
    autor = models.ForeignKey(Autor)
    title = models.CharField(max_length=100)
    year = models.CharField(max_length=20)

Please tell me how to add a few more books to an existing author through ORM.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2017-02-10
@petermzg

book = Books(autor_id = id, title = 'title', year = '2017')
book.save()

I
iegor, 2017-02-10
@iegor

autor.books.add(books)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question