Need help with Rent a bike project

Hi, i am going through Django and Python courses.

I am stuck on Djaunty Rent-a-Bike project.

Can someone please take a look at and tell me what i did wrong?


from django.db import models import datetime BASE_PRICE = 25.00 TANDEM_SURCHARGE = 15.00 ELECTRIC_SURCHARGE = 25.00 # Create your models here. class Bike(models.Model): STANDARD = "ST" TANDEM = "TA" ELECTRIC = "EL" BIKE_TYPE_CHOICES = [ (STANDARD, "Standard"), (TANDEM, "Tandem"), (ELECTRIC, "Electric"), ] bike_type = models.CharField(max_length=2, choices=BIKE_TYPE_CHOICES, default=STANDARD) color = models.CharField(max_length=10, default='') 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 f'{self.first_name} {self.last_name} {}' class Rental(models.Model): bike = models.ForeignKey(Bike, on_delete=CASCADE) renter = models.ForeignKey(Renter, on_delete=CASCADE) date = models.DateField( price = models.FloatField(default=0.0) def calc_price(self): curr_price = BASE_PRICE if == "TA": curr_price += TANDEM_SURCHARGE elif == "EL": curr_price += ELECTRIC_SURCHARGE else self.renter.vip_num > 0: curr_price *= 0.8 self.price = curr_price

Just to add, the error appears when i try to makemigrations

Your code throws an error on a specific line mentioning a syntax error which normally means there’s something it can’t quite understand. It might be worth quickly reviewing the syntax of an if statement and in particular the way each clause is laid out. The error is most definitely on that line.

Thanks, i tried a few approaches, but i still get error when i want to makemigrations :confused:

I think you might just be overthinking it just a touch when dealing with this framework, the given error is definitely related to just that one line.

There are certain rules about what you can and cannot write for each of these clauses, if you have older code where you’ve done this that might help or write a quick example for yourself.

  if == "TA":
  elif == "EL":
  else self.renter.vip_num > 0:

Thank you, i don’t know about the old code, because i am following the course, but i think it is a bit outdated.

I don’t think he meant ‘old’ as in ‘from long ago.’ I believe he meant that you probably have some code that you’ve written prior to now that uses if...elif...else that worked correctly. The code you’ve written, as @tgrtim has explained, contains a syntax error on the line indicated by the error message. If you review the proper syntax for such a structure, the error will become glaringly obvious.

1 Like

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