Defining many-to-one relationships with models.ForeignKey

Now, we will create the models that we will use to represent and persist the drone categories, drones, pilots, and competitions, and their relationships. Open the drones/ file and replace its contents with the following code. The lines that declare fields related to other models are highlighted in the code listing. The code file for the sample is included in the hillar_django_restful_06_01 folder, in the restful01/drones/ file.

from django.db import models   class DroneCategory(models.Model):     name = models.CharField(max_length=250)      class Meta:         ordering = ('name',)      def __str__(self):         return   class Drone(models.Model):  name = models.CharField(max_length=250) ...

Get Django RESTful Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.