save channel only once
This commit is contained in:
parent
addb614d4d
commit
37117407b0
1 changed files with 7 additions and 3 deletions
|
@ -32,14 +32,16 @@ class Channel(models.Model):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
program = self.program.order_by('-start')
|
program = self.program.order_by('-start')
|
||||||
|
changed = False
|
||||||
while program.count() < 1 or program[0].end < now:
|
while program.count() < 1 or program[0].end < now:
|
||||||
not_played = items.exclude(program__in=self.program.filter(run=self.run))
|
not_played = items.exclude(program__in=self.program.filter(run=self.run))
|
||||||
not_played_count = not_played.count()
|
not_played_count = not_played.count()
|
||||||
if not_played_count == 0:
|
if not_played_count == 0:
|
||||||
self.run += 1
|
self.run += 1
|
||||||
self.save()
|
changed = True
|
||||||
not_played = items
|
not_played = items
|
||||||
if not_played.count() > 1:
|
not_played_count = not_played.count()
|
||||||
|
if not_played_count > 1:
|
||||||
not_played = not_played.exclude(id=program[0].id)
|
not_played = not_played.exclude(id=program[0].id)
|
||||||
not_played_count = not_played.count()
|
not_played_count = not_played.count()
|
||||||
item = not_played[randint(0, not_played_count-1)]
|
item = not_played[randint(0, not_played_count-1)]
|
||||||
|
@ -55,6 +57,8 @@ class Channel(models.Model):
|
||||||
p.channel = self
|
p.channel = self
|
||||||
p.save()
|
p.save()
|
||||||
program = self.program.order_by('-start')
|
program = self.program.order_by('-start')
|
||||||
|
if changed:
|
||||||
|
self.save()
|
||||||
return program[0].json(user, now)
|
return program[0].json(user, now)
|
||||||
|
|
||||||
class Program(models.Model):
|
class Program(models.Model):
|
||||||
|
|
Loading…
Reference in a new issue