def create(request): if request.method == 'GET': context = { 'form': CreateForm() } return render(request, 'addrbook/create.html', context) entry = Entry(created_by=request.user, creation_time=datetime.now(), updated_by=request.user, update_time=datetime.now()) create_form = CreateForm(request.POST, request.FILES, instance=entry) if not create_form.is_valid(): context = { 'form': create_form } return render(request, 'addrbook/create.html', context) # Save the new record (note: this sets value for entry.id) create_form.save() if create_form.cleaned_data['picture']: url = s3_upload(create_form.cleaned_data['picture'], entry.id) entry.picture_url = url entry.save() message = 'Entry created' edit_form = EditForm(instance=entry) context = { 'message': message, 'entry': entry, 'form': edit_form } return render(request, 'addrbook/edit.html', context)
def create(request): if request.method == 'GET': context = {'form': CreateForm()} return render(request, 'addrbook/create.html', context) create_form = CreateForm(request.POST) if not create_form.is_valid(): context = {'form': create_form} return render(request, 'addrbook/create.html', context) dummy_entry = {'id': 1} for field in [ 'last_name', 'first_name', 'birthday', 'address', 'city', 'state', 'zip_code', 'country', 'email', 'home_phone', 'cell_phone', 'fax', 'spouse_last', 'spouse_first', 'spouse_birth', 'spouse_cell', 'spouse_email' ]: dummy_entry[field] = create_form.cleaned_data[field] dummy_entry['created_by'] = request.user dummy_entry['creation_time'] = timezone.now() dummy_entry['updated_by'] = request.user dummy_entry['update_time'] = timezone.now() message = 'Entry created' edit_form = EditForm(dummy_entry) context = {'message': message, 'entry': dummy_entry, 'form': edit_form} return render(request, 'addrbook/edit.html', context)
def create(request): if request.method == 'GET': context = { 'form': CreateForm() } return render(request, 'addrbook/create.html', context) entry = Entry(created_by=request.user, creation_time=datetime.now(), updated_by=request.user, update_time=datetime.now()) create_form = CreateForm(request.POST, instance=entry) if not create_form.is_valid(): context = { 'form': create_form } return render(request, 'addrbook/create.html', context) # Save the new record create_form.save() message = 'Entry created' edit_form = EditForm(instance=entry) context = { 'message': message, 'entry': entry, 'form': edit_form } return render(request, 'addrbook/edit.html', context)