I have the following model :
class Travel(models.Model):
purpose = models.CharField(max_length=250, null=True)
amount = models.IntegerField()
class TravelSection(models.Model):
travel = models.ForeignKey(Travel, related_name='sections', on_delete=models.CASCADE)
isRoundTrip = models.BooleanField(default=True)
distance = models.FloatField()
transportation = models.CharField(max_length=250)
I create object without using the database :
mytravel = Travel(
purpose='teaching',
amount=1
)
mysection = TravelSection(
travel=mytravel,
isRoundTrip=True,
distance=500,
transportation='train'
)
When I try to access mytravel.sections
, I can't access to the field distance
and other fields. How can I do this without having to save in the database? I don't want to create objects in the database, because I'm trying to make some preprocessing.