示例#1
0
def create():
    u1 = User(first_name="u1", last_name='u1')
    u1.save()
    u2 = User(first_name="u2", last_name='u2')
    u2.save()
    u3 = User(first_name="u3", last_name='u3')
    u3.save()

    blog1 = Blog(title="blog1")
    blog1.author = u1
    blog1.save()
    blog2 = Blog(title="blog2")
    blog2.author = u1
    blog2.save()

    blog1.subscribers.add(u1, u2)
    blog1.save()
    blog2.subscribers.add(u2)
    blog2.save()

    topic1 = Topic(title="topic1")
    topic1.blog = blog1
    topic1.author = u1
    topic1.save()

    topic2_content = Topic(title="topic2_content", created="2017-01-01")
    topic2_content.blog = blog1
    topic2_content.author = u3
    topic2_content.save()

    topic1.likes.add(u1, u2, u3)
    topic1.save()
示例#2
0
def create():
    # Создать пользователя first_name = u1, last_name = u1.
    user1 = User()
    user1.first_name, user1.last_name = "u1", "u1"
    user1.save()

    # Создать пользователя first_name = u2, last_name = u2.
    user2 = User()
    user2.first_name, user2.last_name = "u2", "u2"
    user2.save()

    # Создать пользователя first_name = u3, last_name = u3.
    user3 = User(first_name="u3", last_name="u3")
    user3.save()

    # Создать блог title = blog1, author = u1.
    blog1 = Blog()
    blog1.title = "blog1"
    blog1.author = user1
    blog1.save()

    # Создать блог title = blog2, author = u1.
    blog2 = Blog.objects.create(title="blog2", author=user1)

    # Подписать пользователей u1 u2 на blog1, u2 на blog2.
    u1u2s = User.objects.filter(Q(first_name='u1') | Q(first_name='u2'))
    b1s = Blog.objects.filter(title='blog1')
    # b2 = Blog.objects.filter(title='blog2')
    # u2s = User.objects.filter(first_name='u2')

    for user in u1u2s:
        for b1 in b1s:
            b1.subscribers.add(user)

    blog2.subscribers.add(user2)

    # Создать топик title = topic1, blog = blog1, author = u1.
    topic1 = Topic.objects.create(title='topic1', blog=blog1, author=user1)

    # Создать топик title = topic2_content, blog = blog1, author = u3, created = 2017-01-01.
    topic2 = Topic.objects.create(title='topic2_content',
                                  blog=blog1,
                                  author=user3,
                                  created='2017-01-01')

    # Лайкнуть topic1 пользователями u1, u2, u3.
    topic1.likes.add(user1, user2, user3)