Skip to content

Commit 0574695

Browse files
renzonrenzon
authored andcommitted
Implemented addition of students on admin
close #455
1 parent d9fd333 commit 0574695

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

pythonpro/cohorts/admin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ class ClassInline(admin.TabularInline):
1010
ordering = ('start',)
1111

1212

13+
class StudentInline(admin.TabularInline):
14+
readonly_fields = ('added',)
15+
extra = 1
16+
autocomplete_fields = ['user']
17+
model = Cohort.students.through
18+
ordering = ('added',)
19+
20+
1321
class WebinarInline(admin.StackedInline):
1422
extra = 1
1523
model = Webinar
@@ -18,8 +26,8 @@ class WebinarInline(admin.StackedInline):
1826

1927

2028
@admin.register(Cohort)
21-
class ModuleAdmin(admin.ModelAdmin):
22-
inlines = [ClassInline, WebinarInline]
29+
class CohortAdmin(admin.ModelAdmin):
30+
inlines = [ClassInline, WebinarInline, StudentInline]
2331
prepopulated_fields = {'slug': ('title',)}
2432
list_display = 'title start end page_link'.split()
2533
ordering = ('-start',)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 2.0.6 on 2018-06-12 15:05
2+
3+
import datetime
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('cohorts', '0003_webinar'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='cohortstudent',
16+
name='added',
17+
field=models.DateTimeField(default=datetime.datetime(2018, 6, 12, 0, 0)),
18+
),
19+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0.6 on 2018-06-12 15:06
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('cohorts', '0004_cohortstudent_added'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='cohortstudent',
15+
name='added',
16+
field=models.DateTimeField(auto_now_add=True),
17+
),
18+
]

pythonpro/cohorts/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def get_absolute_url(self):
2121

2222

2323
class CohortStudent(models.Model):
24+
added = models.DateTimeField(auto_now_add=True)
2425
cohort = models.ForeignKey(Cohort, on_delete=models.DO_NOTHING)
2526
user = models.ForeignKey(get_user_model(), on_delete=models.DO_NOTHING)
2627

0 commit comments

Comments
 (0)