예제 #1
0
파일: views.py 프로젝트: underlost/Replica
def TopicEdit(request, guid):
    topic = get_object_or_404(Topic, guid=guid, user=request.user)
    if request.method == "POST":
        f = TopicModelForm(request.POST or None, request.FILES, instance=topic)
        if f.is_valid():
            f.save()
            messages.add_message(request, messages.INFO, "Topic successfully changed.")
            return redirect("Replica:EditTopic", guid=topic.guid)
    else:
        f = TopicModelForm(instance=topic)
    ctx = {"form": f, "topic": topic, "adding": False}
    return render(request, "replica/dashboard/edit-topic.html", ctx)
예제 #2
0
파일: views.py 프로젝트: underlost/Replica
def TopicNew(request):
    instance = Topic(user=request.user)
    if request.method == "POST":
        f = TopicModelForm(request.POST or None, request.FILES, instance=instance)
        if f.is_valid():
            f.save()
            messages.add_message(request, messages.INFO, "New Topic.")
            return redirect("Replica:EditTopic", guid=instance.guid)
    else:
        f = TopicModelForm(instance=instance)
    ctx = {"form": f, "adding": True}
    return render(request, "replica/dashboard/edit-topic.html", ctx)