def create(): u1 = User(first_name="u1", last_name="u1") u2 = User(first_name="u2", last_name="u2") u3 = User(first_name="u3", last_name="u3") u1.save() u2.save() u3.save() b1 = Blog(title="blog1", author=u1) b2 = Blog(title="blog2", author=u1) b1.save() b2.save() b1.subscribers.add(u1, u2) b2.subscribers.add(u2) t1 = Topic(title="topic1", blog=b1, author=u1) t2 = Topic(title="topic2_content", blog=b1, author=u3, created="2017-01-01") t1.save() t2.save() t1.likes.add(u1, u2, u3)
def create(): user1 = User(first_name='u1', last_name='u1') user1.save() user2 = User(first_name='u2', last_name='u2') user2.save() user3 = User(first_name='u3', last_name='u2') user3.save() blog1 = Blog(title='blog1', author=user1) blog1.save() blog2 = Blog(title='blog2', author=user2) blog2.save() blog1.subscribers.add(user1, user2) blog2.subscribers.add(user2) topic1 = Topic(title='topic1', blog=blog1, author=user1) topic1.save() topic2 = Topic(title='topic2_content', blog=blog1, author=user3, created=datetime.date(2017, 1, 1)) topic2.save() topic2.likes.add(user1, user2, user3)
def create(): u1 = User(id=1, first_name='u1', last_name='u1') u2 = User(id=2, first_name='u2', last_name='u2') u3 = User(id=3, first_name='u3', last_name='u3') u1.save() u2.save() u3.save() blog1 = Blog(id=1, title='blog1', author=u1) blog2 = Blog(id=2, title='blog2', author=u1) blog1.save() blog2.save() blog1.subscribers.add(u1, u2) blog2.subscribers.add(u2) blog1.save() blog2.save() topic1 = Topic(id=1, title='topic1', blog=blog1, author=u1) topic2 = Topic(id=2, title='topic2_content', blog=blog1, author=u3, created=timezone.datetime(2017, 1, 1, tzinfo=pytz.UTC)) topic1.save() topic2.save() topic1.likes.add(u1, u2, u3) topic1.save() topic2.save()
def create(): """ Создать пользователя first_name = u1, last_name = u1. Создать пользователя first_name = u2, last_name = u2. Создать пользователя first_name = u3, last_name = u3. Создать блог title = blog1, author = u1. Создать блог title = blog2, author = u1. Подписать пользователей u1 u2 на blog1, u2 на blog2. Создать топик title = topic1, blog = blog1, author = u1. Создать топик title = topic2_content, blog = blog1, author = u3, created = 2017-01-01. Лайкнуть topic1 пользователями u1, u2, u3. :return: """ 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", author=u1) blog1.save() blog2 = Blog(title="blog2", author=u1) blog2.save() blog1.subscribers.add(u1, u2) blog1.save() blog2.subscribers.add(u2) blog2.save() topic1 = Topic(title="topic1", blog=blog1, author=u1) topic1.save() topic2 = Topic(title="topic2_content", blog=blog1, author=u3, created=datetime(2017, 1, 1)) topic2.save() topic1.likes.add(u1, u2, u3) topic1.save()
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()
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)
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', author=u1) blog1.save() blog2 = Blog(title='blog2', author=u2) blog2.save() blog1.subscribers.add(u1, u2) blog2.subscribers.add(u2) topic1 = Topic(title='topic1', blog=blog1, author=u1) topic2 = Topic(title='topic_content', blog=blog1, author=u3, created='2017-01-01') topic1.save() topic2.save() topic1.likes.add(u1, u2, u3)
def api_create_blog(request, *, name, summary, content): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) yield from blog.save() return blog
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', author=u1) blog1.save() blog2 = Blog(title='blog2', author=u1) blog2.save() blog1.subscribers.add(u1, u2) blog1.save() blog2.subscribers.add(u2) blog2.save() topic1 = Topic(title='topic1', blog=blog1, author=u1) topic1.save() topic2 = Topic(title='topic2_content', blog=blog1, author=u3, created=datetime(year=2017, month=1, day=1, tzinfo=UTC)) topic2.save() topic1.likes.add(u1, u2, u3) topic1.save()