Python-Django Web App Course: Djaunty Rent-a-Bike

I am going throught the new Django Web App course, and I’m stuck on Step 19 of the Djaunty Rent-a-Bike project. I have populated my Renter and Bike tables with multiple instances, but when I try to add a new Rental instance using the method shown in the hint for Step 19, I get the following error:

>>> first_bike = Bike.objects.first()
>>> first_renter = Renter.objects.first()
>>> example_rental = Rental(bike=first_bike, renter=first_renter)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: object() takes no parameters

Here is my file:

from django.db import models
import datetime

BASE_PRICE = 25.00

# Bike model class
class Bike(models.Model):

    (STANDARD, "Standard"),
    (TANDEM, "Tandem"),
    (ELECTRIC, "Electric"),

  # bike_type attribute
  bike_type = models.CharField(max_length=2, choices=BIKE_TYPE_CHOICES, default=STANDARD)

  # color attribute
  color = models.CharField(max_length=10, default="")

  # __str__ override
  def __str__(self):
    return self.bike_type + " - " + self.color

class Renter(models.Model):
  first_name = models.CharField(max_length=30)
  last_name = models.CharField(max_length=30)
  phone = models.CharField(max_length=15)
  vip_num = models.IntegerField(default=0)

  def __str__(self):
    return self.first_name + " - #" +

class Rental:
  bike = models.ForeignKey(Bike, on_delete=models.CASCADE)
  renter = models.ForeignKey(Renter,on_delete=models.CASCADE)
  date = models.DateField(
  price = models.FloatField(default=0.0)

  def calc_price():
    curr_price = BASE_PRICE

    if == "TA":
      curr_price += TANDEM_SURCHARGE
    elif == "EL":
      curr_price += ELECTRIC_SURCHARGE
    elif self.renter.vip_num > 0:
      curr_price *= 0.8
    self.price = curr_price

I am lost as to where this error could be coming from, from what I can see I’ve followed all the steps correctly.

Take a look at your Rental model. It’s different to the others in one very important way.

You’ve missed something out when defining the class…

1 Like

:man_facepalming: how did I miss that…thank you!

1 Like

What did you miss? I don’t seem to find what’s missing. Is it returning the vip_number?

Never mind I found it. Models.Model

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.