Friday, March 28, 2014



I've been trying to create a simple flight booking system but seem to have trouble.

When trying to create a Flight object it says that aircraft_id may not be null
and when trying to set a Passenger object it says flight_id may not be null

Here is my file

from django.db import models
  2 from django.utils import timezone
  3 import datetime
 # Create your models here.
class Aircraft(models.Model):
   aircraft_model = models.CharField(max_length=30)
   aircraft_num_seats = models.IntegerField(default=50)
   available = models.BooleanField(default=False)
   def __unicode__(self):
       return "%s , %d , %s" % (self.aircraft_model,self.aircraft_num_seats,self.available)
class Passenger(models.Model):
   passenger_name = models.CharField(max_length=30,default="John")
   passenger_surname= models.CharField(max_length=30,default="Doe")
   def __unicode__(self):
       return "%s %s"% (self.passenger_name,self.passenger_surname)
class Flight(models.Model):
   aircraft = models.ForeignKey(Aircraft)
   passengers = models.ManyToManyField(Passenger)
   num_seat_available = models.IntegerField(default=50) # requires method to calculate this
   departFrom = models.CharField(max_length=50)
   departTo = models.CharField(max_length=50)
   departTime = models.DateTimeField(
   flight_duration = models.IntegerField(default=0) # requires method to calculate this
   arrival = models.DateTimeField(default =
   cancel_flight = models.BooleanField(default=False)
   def __unicode__(self):
      return "%s --> %s , %s --> %s" % (self.departFrom,self.departTo,str(self.departTime),str(self.arrival))


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment