Skip to content

Commit

Permalink
Merge pull request #31 from project-lovelace/reorder-problems
Browse files Browse the repository at this point in the history
Reorder problems
  • Loading branch information
ali-ramadhan authored Jul 8, 2019
2 parents 17aa6b2 + c52cf19 commit e0afe2e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/problems/migrations/0006_reorder-problems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1.5 on 2019-07-08 16:09

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('problems', '0005_extended_submission_model'),
]

operations = [
migrations.AddField(
model_name='problem',
name='order_id',
field=models.IntegerField(null=True, unique=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]
3 changes: 3 additions & 0 deletions src/problems/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Problem(models.Model):

id = models.AutoField(primary_key=True)

# The order of the problems in the problem list/table.
order_id = models.IntegerField(unique=True, validators=[MinValueValidator(0)], editable=True, null=True)

# Unique name for database and urls, e.g. "earthquake-epicenters".
name = models.CharField(unique=True, max_length=256, editable=True)

Expand Down
2 changes: 1 addition & 1 deletion src/problems/templates/problems/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{% for problem in latest_problem_list %}
{% if problem.visible %}
<tr>
<th>{{ problem.id }}</th>
<th>{{ problem.order_id }}</th>
<th>
{% if user.is_authenticated %}
{% if problem.id in problems_solved %}
Expand Down
4 changes: 2 additions & 2 deletions src/problems/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class IndexView(generic.ListView):
context_object_name = 'latest_problem_list'

def get_queryset(self):
"""Return all problems, sorted chronologically."""
return Problem.objects.order_by('date_added')
"""Return all problems, sorted by order ID."""
return Problem.objects.order_by('order_id')

def get_context_data(self, **kwargs):
""" Add a list of problems solved by the user, if authenticated. """
Expand Down

0 comments on commit e0afe2e

Please sign in to comment.