def country_new(request): if request.method == "POST": form = CountryForm(request.POST, request.FILES) if form.is_valid(): country = form.save(commit=False) country.save() form.save_m2m() return redirect('website.views.country_detail', pk=country.pk) else: form = CountryForm() return render(request, 'website/country_new.html', {'form': form})
def country_edit(request, pk): country = get_object_or_404(Country, pk=pk) if request.method == "POST": form = CountryForm(request.POST, request.FILES, instance=country) if form.is_valid(): country = form.save(commit=False) country.save() form.save_m2m() return redirect('website.views.country_detail', pk=country.pk) else: form = CountryForm(instance=country) return render(request, 'website/country_new.html', {'form': form})