Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Customizing the Django Admin Customizing the List View Test: Custom Attributes

"unsupported operand type(s)" - What's wrong with my solution?

I'm getting the following error on my solution here:

"unsupported operand type(s) for *: 'FakeQuiz' and 'float'"

Can anyone tell me what's wrong with my code? Thanks in advance!

courses/models.py
from django.db import models
import math 

class Step(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    order = models.IntegerField(default=0)

    class Meta:
        abstract = True
        ordering = ['order',]

    def __str__(self):
        return self.title

class Quiz(Step):
    total_questions = models.IntegerField()

    def number_correct_needed(questions):
        return '{}/{}'.format(math.ceil(questions * .7), total_questions)
courses/admin.py
from django.contrib import admin 

from . import models

class QuizAdmin(admin.ModelAdmin):
    list_display = ['title', 'course']

2 Answers

I was being careless. Figured it out but then forgot to wrap everything in a function. Here's what finally worked:

class Quiz(Step):
    total_questions = models.IntegerField()
    def number_correct_needed(self):
        return '{}/{}'.format(math.ceil(self.total_questions * .7), self.total_questions)

What is the data type for the questions variable in Quiz.number_correct_needed()?

That's the only place in your code I'm seeing the * operator used on a variable, and a float.

Okay I'm embarrassed - I had things pretty backwards. I don't even need that extra questions variable. Trying this line now but it's still not working, just saying "Bummer, try again!"

return '{}/{}'.format(math.ceil(total_questions * .7), total_questions)

Sorry, figured it out. Forgot to put everything in a function. Relaxed a little too much over the holidays I guess. Thank you for your help!