Step 8 (S-60814)

From Stepik Wiki
Revision as of 13:17, 13 March 2017 by Admin (Talk | contribs) (Create page for step id=60814)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Step on Stepik: https://stepik.org/lesson/14830/step/8


Допустим имеются следующие модели.


class Author(models.Model):
    rating = models.IntegerField()
    name = models.CharField(max_length=50)

class Article(models.Model):
    author = models.ForeignKey(Author)
    text = models.TextField()


Выберите правильные способы создания нового объекта статьи (Article) для данного автора (объект author)

A)



article = Article(author=author, text=text); article.save()


B)

article = author.article_set.create(text=text)


C)

article = Article.objects.create(text=text, author=author)


D)

article = Article.objects.create(text=text, author_id=author.id)