I have a simple app which asks a user if they have completed their hour task (such as getting up from the desk and streching)
however, my form is not rendering and I'm non the wiser to why after debugging for a good while.
models.py
from django.db import models
from django.contrib.auth import get_user_model
class StrechesTracker(models.Model):
id = models.AutoField(
primary_key=True,
editable=False
)
excercise = models.BooleanField(
choices=(
(True,'Yes'), (False,'No')
)
)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, null=True)
def __str__(self) -> str:
return self.excercise
forms.py
from django import forms
from .models import StrechesTracker
class StrechForm(forms.ModelForm):
class Meta:
model = StrechesTracker
fields = '__all__'
views.py
from typing import Any, Dict
from django.views.generic import CreateView
from .models import StrechesTracker
from .forms import StrechForm
class TrackerView(CreateView):
model = StrechesTracker
form_class = StrechForm
template_name = 'home.html'
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
context = super().get_context_data(**kwargs)
return context
def form_valid(self, form: StrechForm):
return super().form_valid(form)
home.html
{% extends "_base.html" %} {% load crispy_forms_tags %} {% block content %}
<div class="jumbotron">
<h1>Done Hourly Streches?</h1>
<form action="" method="post">
{% csrf_token %} {{ form|crispy }}
<button class="btn btn-success" type="submit">Yes</button>
</form>
</div>
{% endblock content %}
Additional info.
unsure if this is required but this is the table definition for my model
CREATE TABLE public.tracker_strechestracker
(
id integer NOT NULL DEFAULT nextval('tracker_strechestracker_id_seq'::regclass),
excercise boolean NOT NULL,
created_at timestamp with time zone NOT NULL,
created_by_id bigint
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.tracker_strechestracker
OWNER to postgres;
screen grab of page.

