I would like to create a site that would show list of tournaments. Tournament may take place more times per day repeatedly. I'll give an example:
Tournament 1:
- Monday 16:00
- Monday 18:00
- Tuesday 16:00
- Tuesday 18:00
- Friday 16:00
- Friday 18:00
I would like to avoid duplicity, so I use m2m on days and times:
class Day(models.Model):
name = models.CharField(max_length=10)
weekday = models.IntegerField()
def __unicode__(self):
return self.name
class Time(models.Model):
time = models.TimeField()
class Tournament(models.Model):
name = models.CharField("Tournament name", max_length=200)
currency = models.CharField(max_length=5, choices=CURRENCIES, default='USD')
prize = models.DecimalField(max_digits=20, decimal_places=2)
entry = models.DecimalField(max_digits=20, decimal_places=2, default=0)
fee = models.DecimalField(max_digits=20, decimal_places=2, default=0)
password = models.CharField("password", max_length=200, null=True, blank=True)
tournament_id = models.CharField("Tournament ID", max_length=50, null=True, blank=True)
number_of_players = models.DecimalField(max_digits=20, decimal_places=0, default='0', null=True, blank=True)
type = models.ManyToManyField('room.Type')
room = models.ManyToManyField('room.Room')
requirements_difficulty = models.IntegerField('Tournament Difficulty',validators=[MinValueValidator(1), MaxValueValidator(30)],null=True, blank=True)
requirements_text = models.CharField("Requirements Description", default='no requirements', max_length=1000,null=True, blank=True)
days = models.ManyToManyField(Day, related_name='days')
times = models.ManyToManyField(Time, related_name='times')
There are more parameters, but important are only last two. I create times and days to add as many hours and days as I wish.
Problem is with timezone. TimeField is not timezone aware. I wanted user to select days and then hours. Is it somehow possible to create this functionality timezone aware?
I guess I could store it in db separately and then create timezone aware datetime objects in views.py Correct? What is the best way here?