diff --git a/src/gameservers/admin.py b/src/gameservers/admin.py index 00dec50..b257e16 100644 --- a/src/gameservers/admin.py +++ b/src/gameservers/admin.py @@ -1,13 +1,13 @@ from django.contrib import admin -from .models import Server, Population +from .models import Server, PopulationHistory class ServerAdmin(admin.ModelAdmin): list_display = ['title', 'site_url'] -class PopulationAdmin(admin.ModelAdmin): +class PopulationHistoryAdmin(admin.ModelAdmin): list_display = ['timestamp', 'server', 'players'] admin.site.register(Server, ServerAdmin) -admin.site.register(Population, PopulationAdmin) +admin.site.register(PopulationHistory, PopulationHistoryAdmin) diff --git a/src/gameservers/management/commands/update_population.py b/src/gameservers/management/commands/update_population.py index d6f4e79..9ac418c 100755 --- a/src/gameservers/management/commands/update_population.py +++ b/src/gameservers/management/commands/update_population.py @@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand -from gameservers.models import Server, Population +from gameservers.models import Server, PopulationHistory import re import logging @@ -104,7 +104,7 @@ class Command(BaseCommand): ) ) - pop = Population.objects.create( + pop = PopulationHistory.objects.create( server=server, players=data['player_count'], ) diff --git a/src/gameservers/migrations/0006_auto_20150218_2033.py b/src/gameservers/migrations/0006_auto_20150218_2033.py new file mode 100644 index 0000000..af47e9b --- /dev/null +++ b/src/gameservers/migrations/0006_auto_20150218_2033.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('gameservers', '0005_auto_20150218_2029'), + ] + + operations = [ + migrations.CreateModel( + name='PopulationHistory', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('timestamp', models.DateTimeField(auto_now_add=True)), + ('players', models.PositiveIntegerField()), + ('server', models.ForeignKey(to='gameservers.Server')), + ], + options={ + 'ordering': ['timestamp', 'server'], + }, + bases=(models.Model,), + ), + migrations.RemoveField( + model_name='population', + name='server', + ), + migrations.DeleteModel( + name='Population', + ), + ] diff --git a/src/gameservers/models.py b/src/gameservers/models.py index 91e6666..b9d7001 100644 --- a/src/gameservers/models.py +++ b/src/gameservers/models.py @@ -12,7 +12,7 @@ class Server(models.Model): def __str__(self): return self.title -class Population(models.Model): +class PopulationHistory(models.Model): timestamp = models.DateTimeField(auto_now_add=True) server = models.ForeignKey(Server) players = models.PositiveIntegerField() diff --git a/src/gameservers/views.py b/src/gameservers/views.py index 019de01..6847073 100644 --- a/src/gameservers/views.py +++ b/src/gameservers/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render from django.views import generic -from .models import Server, Population +from .models import Server, PopulationHistory class ServerListView(generic.ListView): model = Server @@ -13,6 +13,6 @@ class ServerDetailView(generic.DetailView): context = super(ServerDetailView, self).get_context_data(**kwargs) server = context['server'] # HACK: 24 hours for the last 3 days, might want to change this - context['population'] = Population.objects.filter(server=server)[:3*24] + context['population'] = PopulationHistory.objects.filter(server=server)[:3*24] return context