def tank_species_create(request, tank_id=None): form = SpeciesForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.tank_id = tank_id instance.save() messages.success(request, 'Successfully Created') return redirect(get_abs_url('tdetail_s', 'tank_id', tank_id)) context = { 'form': form, } return render(request, 'aquarium/generic_form.html', context)
def edit_species(request, pk): species = Species.objects.get(pk=pk) form = SpeciesForm(request.POST or None, instance=species) if request.method == "POST" and form.is_valid(): if "cancel" in request.POST: return redirect('/annotations/species/%s' % pk) with reversion.create_revision(): form.save() reversion.set_user(request.user) comment = request.POST['comment'] or "Changed tissue" reversion.set_comment(comment) log(request, species, comment) return redirect('/annotations/species/%s.html' % pk) ctx = {'species': species, 'form': form, 'action': 'Edit'} return render_to_response('annotations/species_form.html', ctx, context_instance=RequestContext(request))