You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

24 lines
849 B

import random
from django.db import models
class Zone(models.Model):
ETATS = (
('L', 'Libre'),
('A', 'Attibuée'),
('O', 'Occupée'),
)
nom = models.CharField(max_length=50)
etat = models.CharField(max_length=1, choices=ETATS, default = 'L')
code = models.IntegerField(default = random.randint(1000, 9999))
def __str__(self):
return self.nom+" : "+self.get_etat_display()+" ("+str(self.code)+")"
class Distance(models.Model):
zone1 = models.ForeignKey(Zone, related_name='zone1',on_delete=models.CASCADE)
zone2 = models.ForeignKey(Zone, related_name='zone2',on_delete=models.CASCADE)
distance = models.IntegerField()
class Meta:
unique_together = (('zone1','zone2'),)
def __str__(self):
return self.zone1.nom+" -> "+self.zone2.nom+" : "+str(self.distance)