random clip sort
This commit is contained in:
parent
cdd5976d32
commit
8511769885
3 changed files with 14 additions and 10 deletions
|
|
@ -29,14 +29,14 @@ def update_random_sort():
|
|||
|
||||
def update_random_clip_sort():
|
||||
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
||||
random.seed()
|
||||
from clip.models import Clip
|
||||
ids = [f['id'] for f in Clip.objects.values('id')]
|
||||
random.shuffle(ids)
|
||||
n = 1
|
||||
for i in ids:
|
||||
Clip.objects.filter(pk=i).update(random=n)
|
||||
n += 1
|
||||
from django.db import connection, transaction
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('DROP TABLE clip_random;')
|
||||
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')
|
||||
cursor.execute('ALTER TABLE "clip_random" ADD UNIQUE ("clip_id")')
|
||||
cursor.execute('CREATE INDEX "clip_random_clip_id_idx" ON "clip_random" ("clip_id")')
|
||||
cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")')
|
||||
transaction.commit_unless_managed()
|
||||
|
||||
@task(ignore_results=True, queue='default')
|
||||
def update_poster(itemId):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue