Пример #1
0
def add_trend(request):
    context_vars = dict()
    form = TrendForm()
    if request.method == 'POST':
        form = TrendForm(request.POST, request.FILES)
        if form.is_valid():
            trend = form.save(commit=False)
            trend.muaccount = request.muaccount
            trend.save()
            form.save_m2m()
            return HttpResponseRedirect(reverse('tracker_trend_index'))
    context_vars['form'] = form
    return direct_to_template(request, template='tracker/form.html', extra_context=context_vars)
Пример #2
0
def edit_trend(request, trend_id):
    context_vars = dict()
    try:
        trend = Trend.objects.get(id=trend_id)
    except ObjectDoesNotExist:
        raise Http404
    form = TrendForm(instance=trend)
    if request.method == 'POST':
        form = TrendForm(request.POST, request.FILES, instance=trend)
        if form.is_valid():
            trend = form.save()
            return HttpResponseRedirect(reverse('tracker_trend_index'))
    context_vars['form'] = form
    return direct_to_template(request, template='tracker/form.html', extra_context=context_vars)