def addArticle(request): article = Article() article.title = request.POST.get('title', '') article.abstract = request.POST.get('abstract', '') article.category_id = request.POST.get('categorie'); article.content = request.POST.get('content', '') article.author = User.objects.get(id=request.user.id) try: article.save() return HttpResponseRedirect('/articles/read') except: return HttpResponseRedirect('/')
def GenerateOneFakeData(): art = Article() art.title = get_random_str(name_str, 12) art.brief = get_random_str(brief_str) art.content = desc_str art.click_number = randint(10, 100) art.favor_number = randint(10, 100) art.comment_number = randint(10, 100) art.word_count = randint(100, 1000) art.front_image = "articles/images/art.png" # 创建当前文章的用户 art.user_id = users[randint(0, users.count() - 1)].id # 当前文章的类别 art.category_id = categories[randint(0, categories.count() - 1)].id # 为当前文章指定若干tags # art.tags.set(ArticleTag(name=tags[randint(0,tags.count()-1)].name)) return art