Example #1
0
def query_update(request, pk):
    """View for query update to user who added the query."""
    queryu = get_object_or_404(QueryS, pk=pk)
    form = QueryFormS(request.POST or None, instance=queryu)
    if form.is_valid():
        form.save()
        return redirect('home')
    return render(request, 'vtr/update_form.html', {'form': form})
Example #2
0
def add_queryS(request):
    """View for student query form."""
    if request.method == 'POST':
        query_form = QueryFormS(request.POST, request.FILES)
        if query_form.is_valid():
            # is the form valid
            query = query_form.save(commit=False)
            if UserProfileF.objects.filter(user=request.user.id):
                query.branch = UserProfileF.objects.only('department').get(user=request.user).department
            else:
                query.branch = UserProfileS.objects.only('branch').get(user=request.user).branch
            query.user = request.user
            query.save()
            query_form.save_m2m()
            return redirect(home)
        else:
            print query_form.errors  # no, display error to end user
    else:
        query_form = QueryFormS()
    return render(request, 'vtr/add_query.html', {'query_form': query_form},)