def NewPost(request): user = request.user tags_objs = [] files_objs = [] if request.method == 'POST': form = NewPostForm(request.POST, request.FILES) if form.is_valid(): files = request.FILES.getlist('content') caption = form.cleaned_data.get('caption') tags_form = form.cleaned_data.get('tags') tags_list = list(tags_form.split(',')) for tag in tags_list: t, created = Tag.objects.get_or_create(title=tag) tags_objs.append(t) for file in files: file_instance = PostFileContent(file=file, user=user) file_instance.save() files_objs.append(file_instance) p, created = Post.objects.get_or_create(caption=caption, user=user) p.tags.set(tags_objs) p.content.set(files_objs) p.save() return redirect('post:index') else: form = NewPostForm() context = { 'form': form, } return render(request, 'newpost.html', context)
def newPost(request): user = request.user.id tags_objs = [] if request.method == 'POST': form = NewPostForm(request.POST, request.FILES) if form.is_valid(): picture = form.cleaned_data.get('picture') caption = form.cleaned_data.get('caption') tags_from = form.cleaned_data.get('tags') tags_list = list(tags_from.split(';')) for tag in tags_list: t, created = Tag.objects.get_or_create(title=tag) tags_objs.append(t) p, created = Post.objects.get_or_create(picture=picture, caption=caption, user_id=user) p.tags.set(tags_objs) p.save() return redirect('index') else: form = NewPostForm() context = {'form': form} return render(request, 'newpost.html', context)
def NewPost(request): user = request.user.id tags_objs = [] MLP = Post.objects.all().order_by('-likes')[:3] if request.method == 'POST': form = NewPostForm(request.POST, request.FILES) if form.is_valid(): picture = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') tags_form = form.cleaned_data.get('tags') title1 = form.cleaned_data.get('title') tags_list = list(tags_form.split(',')) for tag in tags_list: t, created = Tag.objects.get_or_create(title=tag) tags_objs.append(t) p, created = Post.objects.get_or_create(picture=picture, caption=caption, title=title1, user_id=user) p.tags.set(tags_objs) p.save() return redirect('index') else: form = NewPostForm() context = {'form': form, "MLP": MLP} return render(request, 'create-post.html', context)
def NewPost(request): user = request.user files_objs = [] if request.method == "POST": form = NewPostForm(request.POST, request.FILES) if form.is_valid(): files = request.FILES.getlist('content') title = form.cleaned_data.get('title') caption = form.cleaned_data.get('caption') tier = form.cleaned_data.get('tier') tiers = get_object_or_404(Tier, id=tier.id) for file in files: file_instance = PostFileContent(file=file, user=user, tier=tiers) file_instance.save() files_objs.append(file_instance) p, created = Post.objects.get_or_create(title=title, caption=caption, user=user, tier=tiers) p.content.set(files_objs) p.save() return redirect('index') else: form = NewPostForm() form.fields['tier'].queryset = Tier.objects.filter(user=user) context = { 'form': form, } return render(request, 'newpost.html', context)