How to fix 'workout_details' object has no attribute '_state' Error

I have a problem with showing a queryset of a specific model in my Gym project.

Here is the models:

class Workout(models.Model):
    name = models.CharField(max_length = 30,blank=True, null=True)

class Exercise(models.Model):
    workout = models.ForeignKey(Workout, on_delete=models.CASCADE, related_name='exercises',blank=True, null=True)
    name = models.CharField(max_length = 30, blank=True, null=True)

class Breakdown(models.Model):
    exercise = models.ForeignKey(Exercise, on_delete=models.CASCADE, related_name='excercise',blank=True, null=True)
    repetitions = models.IntegerField(validators=[MinValueValidator(1)],blank=True, null=True)

I am trying to showing the Breakdown details of every Exercise, but I got this error after several trials.

Here is the urls:

urlpatterns = [
    path('', home.as_view(), name='home'),
    path('workout/<int:pk>/', workout_details.as_view(), name='workout'),

Here is the views:

class home(ListView):
    model = Workout
    template_name = 'my_gym/home.html'
    context_object_name = 'workouts'

class workout_details(DetailView):
    model = Exercise.workout
    template_name = 'my_gym/start_workout.html'
    context_object_name = 'exercises'

# class workout_details(DetailView):
#     model = Breakdown
#     template_name = 'my_gym/start_workout.html'
#     context_object_name = 'breakdown'

Here is the template:

{% for excercise in excercises %}

{% for b in breakdown %}

{% endfor %}
{% endfor %}

My question what is my mistake here that is either getting me an error or not showing the required data set. my objective is the choose from the home page a Workout from list and next page to be the list of exercises with the repitions related to it.

Back to Top