diff --git a/pythonpro/cohorts/admin.py b/pythonpro/cohorts/admin.py index 081a13e0..98a81104 100644 --- a/pythonpro/cohorts/admin.py +++ b/pythonpro/cohorts/admin.py @@ -10,6 +10,14 @@ class ClassInline(admin.TabularInline): ordering = ('start',) +class StudentInline(admin.TabularInline): + readonly_fields = ('added',) + extra = 1 + autocomplete_fields = ['user'] + model = Cohort.students.through + ordering = ('added',) + + class WebinarInline(admin.StackedInline): extra = 1 model = Webinar @@ -18,8 +26,8 @@ class WebinarInline(admin.StackedInline): @admin.register(Cohort) -class ModuleAdmin(admin.ModelAdmin): - inlines = [ClassInline, WebinarInline] +class CohortAdmin(admin.ModelAdmin): + inlines = [ClassInline, WebinarInline, StudentInline] prepopulated_fields = {'slug': ('title',)} list_display = 'title start end page_link'.split() ordering = ('-start',) diff --git a/pythonpro/cohorts/migrations/0004_cohortstudent_added.py b/pythonpro/cohorts/migrations/0004_cohortstudent_added.py new file mode 100644 index 00000000..40807a5f --- /dev/null +++ b/pythonpro/cohorts/migrations/0004_cohortstudent_added.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.6 on 2018-06-12 15:05 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cohorts', '0003_webinar'), + ] + + operations = [ + migrations.AddField( + model_name='cohortstudent', + name='added', + field=models.DateTimeField(default=datetime.datetime(2018, 6, 12, 0, 0)), + ), + ] diff --git a/pythonpro/cohorts/migrations/0005_auto_20180612_1206.py b/pythonpro/cohorts/migrations/0005_auto_20180612_1206.py new file mode 100644 index 00000000..a67c61e2 --- /dev/null +++ b/pythonpro/cohorts/migrations/0005_auto_20180612_1206.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.6 on 2018-06-12 15:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cohorts', '0004_cohortstudent_added'), + ] + + operations = [ + migrations.AlterField( + model_name='cohortstudent', + name='added', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/pythonpro/cohorts/models.py b/pythonpro/cohorts/models.py index e36f4cd0..81ed8367 100644 --- a/pythonpro/cohorts/models.py +++ b/pythonpro/cohorts/models.py @@ -21,6 +21,7 @@ def get_absolute_url(self): class CohortStudent(models.Model): + added = models.DateTimeField(auto_now_add=True) cohort = models.ForeignKey(Cohort, on_delete=models.DO_NOTHING) user = models.ForeignKey(get_user_model(), on_delete=models.DO_NOTHING)