Пример #1
0
def create_group(request):
    data = {}

    if request.method == 'POST':
        post = request.POST.copy()
        post['user'] = request.user
        form = GroupForm(post)
        if form.is_valid():
            group = form.save()            
            return redirect(reverse('show_group', 
                                    kwargs=dict(group=group.id)))
    else:
        form = GroupForm()
        
    data['form'] = form
    return render(request, 'accounts/groups/create.html', data)
Пример #2
0
def update_group(request, group):
    data = {}
    group = db.Group.objects.get(pk=group)
    
    if request.method == 'POST':
        post = request.POST.copy()
        post['user'] = request.user
        form = GroupForm(post, instance=group)
        if form.is_valid():
            group = form.save()
            return redirect(reverse('show_group', 
                                    kwargs=dict(group=group.id)))
    else:
        form = GroupForm(instance=group)
        
    data['form'] = form   
    data['group'] = group 
    return render(request, 'accounts/groups/update.html', data)