String Field Lookup

Report a typo

You have two models. One is Engine, with the following fields: type and volume. The other one is Car, with color, engine, and speed set as fields:

class Engine(models.Model):
    type = models.CharField(max_length=32)
    volume = models.IntegerField()


class Car(models.Model):
    color = models.CharField(max_length=32)
    engine = models.ForeignKey(Engine, on_delete=models.CASCADE)
    speed = models.FloatField()

There are many shades of red. Filter the cars that have red as their color; in other words, the color field must contain the substring red. The result must be a QuerySet object.

Sample Input 1:

Sample Output 1:

True
Write a program in Python 3
red_cars = ...
___

Create a free account to access the full topic