Repository: Cloud-CV/EvalAI

Issue:
Add models for creating challenge using zip file.
The models must be defined in `apps/challenges/models.py`.

**Fields:**
- user: ForeignKey to User
- challenge : OneToOneField to Challenge
- zip_configuration: FileField
- is_created: Boolean field
- stdout_file: Filefield
- stderr_file: Filefield



Discussion:

Resolving patch:
diff --git a/apps/challenges/admin.py b/apps/challenges/admin.py
--- a/apps/challenges/admin.py
+++ b/apps/challenges/admin.py
@@ -2,7 +2,13 @@
 
 from base.admin import TimeStampedAdmin
 
-from .models import Challenge, ChallengePhase, DatasetSplit, Leaderboard, ChallengePhaseSplit, LeaderboardData
+from .models import (Challenge,
+                     ChallengeConfiguration,
+                     ChallengePhase,
+                     ChallengePhaseSplit,
+                     DatasetSplit,
+                     Leaderboard,
+                     LeaderboardData,)
 
 
 @admin.register(Challenge)
@@ -45,3 +51,10 @@ class LeaderboardDataAdmin(TimeStampedAdmin):
     list_display = ("challenge_phase_split", "submission", "leaderboard", "result")
     list_filter = ("challenge_phase_split", "submission", "leaderboard", "result")
     search_fields = ("challenge_phase_split", "submission", "leaderboard", "result")
+
+
+@admin.register(ChallengeConfiguration)
+class ChallengeConfigurationAdmin(TimeStampedAdmin):
+    list_display = ('user', 'challenge', 'is_created', 'zip_configuration',)
+    list_filter = ('user', 'is_created',)
+    search_fields = ('user', 'challenge',)
diff --git a/apps/challenges/migrations/0028_zip_configuration_models_for_challenge_creation.py b/apps/challenges/migrations/0028_zip_configuration_models_for_challenge_creation.py
new file mode 100644
--- /dev/null
+++ b/apps/challenges/migrations/0028_zip_configuration_models_for_challenge_creation.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2017-06-11 18:40
+from __future__ import unicode_literals
+
+import base.utils
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+        ('challenges', '0027_adds_unique_to_codename_dataset_split'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='ChallengeConfiguration',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('created_at', models.DateTimeField(auto_now_add=True)),
+                ('modified_at', models.DateTimeField(auto_now=True)),
+                ('zip_configuration', models.FileField(upload_to=base.utils.RandomFileName('zip_configuration_files/challenge_zip'))),
+                ('is_created', models.BooleanField(default=False)),
+                ('stdout_file', models.FileField(blank=True, null=True, upload_to=base.utils.RandomFileName('zip_configuration_files/challenge_zip'))),
+                ('stderr_file', models.FileField(blank=True, null=True, upload_to=base.utils.RandomFileName('zip_configuration_files/challenge_zip'))),
+                ('challenge', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='challenges.Challenge')),
+                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+            ],
+            options={
+                'db_table': 'challenge_zip_configuration',
+            },
+        ),
+    ]
diff --git a/apps/challenges/models.py b/apps/challenges/models.py
--- a/apps/challenges/models.py
+++ b/apps/challenges/models.py
@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 
+from django.contrib.auth.models import User
 from django.utils import timezone
 from django.contrib.postgres.fields import JSONField
 from django.db import models
@@ -183,3 +184,21 @@ def __unicode__(self):
     class Meta:
         app_label = 'challenges'
         db_table = 'leaderboard_data'
+
+
+class ChallengeConfiguration(TimeStampedModel):
+    """
+    Model to store zip file for challenge creation.
+    """
+    user = models.ForeignKey(User)
+    challenge = models.OneToOneField(Challenge, null=True, blank=True)
+    zip_configuration = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'))
+    is_created = models.BooleanField(default=False)
+    stdout_file = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'),
+                                   null=True, blank=True)
+    stderr_file = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'),
+                                   null=True, blank=True)
+
+    class Meta:
+        app_label = 'challenges'
+        db_table = 'challenge_zip_configuration'


Test patch: