Skip to content

Instantly share code, notes, and snippets.

@bennett39
Created July 11, 2022 01:06
Show Gist options
  • Save bennett39/254e152e6cfe5fd527881eeafdaa77b4 to your computer and use it in GitHub Desktop.
Save bennett39/254e152e6cfe5fd527881eeafdaa77b4 to your computer and use it in GitHub Desktop.
from django.shortcuts import render, redirect
from django.views import View
from .models import Calculation
from .tasks import fibonacci_task
class FibonacciView(View):
def get(self, request):
"""Show a form to start a calculation"""
return render(request, 'fib/start.html')
def post(self, request):
"""Process a form & start a Fibonacci calculation"""
n = request.POST['fib_number']
calculation = Calculation.objects.create(
equation=Calculation.EQUATION_FIBONACCI,
input=int(n),
status=Calculation.STATUS_PENDING,
)
fibonacci_task.delay(calculation.id)
return redirect('fibonacci_list')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment