I'd like to take a minute to introduce the ImageField
model field. This is the first time we are seeing it, and using it is a bit different than other model fields. Here is our Car
model that uses this field:
class Car(models.Model): name = models.CharField(max_length=100) image = models.ImageField(upload_to='car_images') description = models.TextField() daily_rent = models.IntegerField() is_available = models.BooleanField() def get_absolute_url(self): return reverse('car-details', kwargs={'pk': self.pk})
ImageField
is special and different from all the other database model fields that we have looked at for a few reasons. Firstly, it needs the Pillow image manipulation library to work, which is why we had to install it at the start of the chapter. If we had tried to run our application without Pillow installed, Django would have complained and never...