FAQ
Hi,

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 models.py file

from django.db import models
   2 from django.utils import timezone
   3 import datetime
   4
  # 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(default=timezone.now())
    flight_duration = models.IntegerField(default=0) # requires method to
calculate this
    arrival = models.DateTimeField(default = timezone.now())
    cancel_flight = models.BooleanField(default=False)

    def __unicode__(self):
       return "%s --> %s , %s --> %s" %
(self.departFrom,self.departTo,str(self.departTime),str(self.arrival))

Thanks

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/edab5b92-756f-4c90-a26e-75cedbe7d2af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Lukas Nemec at Mar 28, 2014 at 3:20 pm
    You need to re-create your database.

    Good way is to create a script that populates your DB with some test
    data, and drop DB after a major change, or when something breaks, and
    re-create it.

    For now, you should try to create different DB (to preserve your data)
    and do
    python manage.py syncdb


    Lukas

    On 03/28/2014 03:24 PM, Warren Jacobus wrote:
    Hi,

    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 models.py file

    from django.db import models
    2 from django.utils import timezone
    3 import datetime
    4
    # 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(default=timezone.now())
    flight_duration = models.IntegerField(default=0) # requires method
    to calculate this
    arrival = models.DateTimeField(default = timezone.now())
    cancel_flight = models.BooleanField(default=False)
    def __unicode__(self):
    return "%s --> %s , %s --> %s" %
    (self.departFrom,self.departTo,str(self.departTime),str(self.arrival))

    Thanks
    --
    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 django-users+unsubscribe@googlegroups.com
    To post to this group, send email to django-users@googlegroups.com
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/edab5b92-756f-4c90-a26e-75cedbe7d2af%40googlegroups.com
    <https://groups.google.com/d/msgid/django-users/edab5b92-756f-4c90-a26e-75cedbe7d2af%40googlegroups.com?utm_medium=email&utm_source=footer>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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 django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/53358BDF.8050806%40gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedMar 28, '14 at 2:46p
activeMar 28, '14 at 3:20p
posts2
users2
websitedjangoproject.com

2 users in discussion

Lukas Nemec: 1 post Warren Jacobus: 1 post

People

Translate

site design / logo © 2022 Grokbase