Commit bf81e85b authored by fred's avatar fred

store basic download count stats in soundfile model

parent 93123efb
......@@ -162,7 +162,7 @@ class EmissionForm(forms.ModelForm):
class EpisodeForm(forms.ModelForm):
class Meta:
model = Episode
exclude = ('slug', 'has_focus', 'got_focus', 'effective_start', 'effective_end')
exclude = ('slug', 'has_focus', 'got_focus', 'effective_start', 'effective_end', 'download_count')
widgets = {'emission': forms.HiddenInput(), 'tags': TagWidget()}
def save(self, commit=True):
......
import urllib.parse
import requests
from django.conf import settings
from django.core.management.base import BaseCommand
from emissions.models import SoundFile
class Command(BaseCommand):
def handle(self, *args, **kwargs):
resp = requests.get(urllib.parse.urljoin(settings.WEBSITE_BASE_URL, '__webstats/downloads.json'))
for soundfile_id, download_count in resp.json():
SoundFile.objects.filter(id=soundfile_id).update(download_count=download_count)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-02-09 10:48
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('emissions', '0015_auto_20200404_1510'),
]
operations = [
migrations.AddField(
model_name='soundfile',
name='download_count',
field=models.IntegerField(default=0, verbose_name='Download Count'),
),
]
......@@ -508,6 +508,9 @@ class SoundFile(models.Model):
got_focus = models.DateTimeField(default=None, null=True, blank=True)
has_focus = models.BooleanField(default=False)
# basic statistics
download_count = models.IntegerField(_('Download Count'), default=0)
creation_timestamp = models.DateTimeField(auto_now_add=True, null=True)
last_update_timestamp = models.DateTimeField(auto_now=True, null=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment