From 9bdd0cf03209ce4db42fa46553050f63c56233a0 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Fri, 25 Sep 2020 16:43:56 +0200 Subject: [PATCH] Add field college to PotentialFellowship --- colleges/admin.py | 2 ++ colleges/forms.py | 2 +- .../0021_potentialfellowship_college.py | 19 ++++++++++++++ .../0022_potentialfellowship_set_college.py | 25 +++++++++++++++++++ .../migrations/0023_auto_20200925_1632.py | 19 ++++++++++++++ colleges/models/potential_fellowship.py | 6 +++++ .../colleges/potentialfellowship_list.html | 2 ++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 colleges/migrations/0021_potentialfellowship_college.py create mode 100644 colleges/migrations/0022_potentialfellowship_set_college.py create mode 100644 colleges/migrations/0023_auto_20200925_1632.py diff --git a/colleges/admin.py b/colleges/admin.py index f0f5c4466..e9e7978dd 100644 --- a/colleges/admin.py +++ b/colleges/admin.py @@ -42,6 +42,8 @@ class PotentialFellowshipAdmin(admin.ModelAdmin): ] list_display = [ '__str__', + 'college', + 'status' ] search_fields = [ 'profile__last_name', diff --git a/colleges/forms.py b/colleges/forms.py index e9b5de2df..a8a812404 100644 --- a/colleges/forms.py +++ b/colleges/forms.py @@ -223,7 +223,7 @@ class PotentialFellowshipForm(RequestFormMixin, forms.ModelForm): class Meta: model = PotentialFellowship - fields = ['profile'] + fields = ['college', 'profile'] def save(self): """ diff --git a/colleges/migrations/0021_potentialfellowship_college.py b/colleges/migrations/0021_potentialfellowship_college.py new file mode 100644 index 000000000..a6fe6c912 --- /dev/null +++ b/colleges/migrations/0021_potentialfellowship_college.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.16 on 2020-09-25 14:25 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('colleges', '0020_auto_20200925_1617'), + ] + + operations = [ + migrations.AddField( + model_name='potentialfellowship', + name='college', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='potential_fellowships', to='colleges.College'), + ), + ] diff --git a/colleges/migrations/0022_potentialfellowship_set_college.py b/colleges/migrations/0022_potentialfellowship_set_college.py new file mode 100644 index 000000000..87903642f --- /dev/null +++ b/colleges/migrations/0022_potentialfellowship_set_college.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.16 on 2020-09-25 14:26 + +from django.db import migrations + + +def assign_college(apps, schema_editor): + College = apps.get_model('colleges.College') + PotentialFellowship = apps.get_model('colleges.PotentialFellowship') + + for f in PotentialFellowship.objects.all(): + college = College.objects.get(acad_field__slug=f.profile.discipline) + f.college = college + f.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('colleges', '0021_potentialfellowship_college'), + ] + + operations = [ + migrations.RunPython(assign_college, + reverse_code=migrations.RunPython.noop), + ] diff --git a/colleges/migrations/0023_auto_20200925_1632.py b/colleges/migrations/0023_auto_20200925_1632.py new file mode 100644 index 000000000..f59e059b8 --- /dev/null +++ b/colleges/migrations/0023_auto_20200925_1632.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.16 on 2020-09-25 14:32 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('colleges', '0022_potentialfellowship_set_college'), + ] + + operations = [ + migrations.AlterField( + model_name='potentialfellowship', + name='college', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='potential_fellowships', to='colleges.College'), + ), + ] diff --git a/colleges/models/potential_fellowship.py b/colleges/models/potential_fellowship.py index 7c829c17e..2c39230ce 100644 --- a/colleges/models/potential_fellowship.py +++ b/colleges/models/potential_fellowship.py @@ -28,6 +28,12 @@ class PotentialFellowship(models.Model): and non-registered people. """ + college = models.ForeignKey( + 'colleges.College', + on_delete=models.PROTECT, + related_name='potential_fellowships' + ) + profile = models.ForeignKey('profiles.Profile', on_delete=models.CASCADE) status = models.CharField(max_length=32, choices=POTENTIAL_FELLOWSHIP_STATUSES, default=POTENTIAL_FELLOWSHIP_IDENTIFIED) diff --git a/colleges/templates/colleges/potentialfellowship_list.html b/colleges/templates/colleges/potentialfellowship_list.html index a319e5136..ee0efb1cf 100644 --- a/colleges/templates/colleges/potentialfellowship_list.html +++ b/colleges/templates/colleges/potentialfellowship_list.html @@ -97,6 +97,7 @@ <th>Name</th> <th>Discipline</th> <th>Expertises</th> + <th>For College</th> <th>Status</th> <th>Latest event</th> </tr> @@ -111,6 +112,7 @@ <div class="single d-inline" data-specialization="{{ expertise|lower }}" data-toggle="tooltip" data-placement="bottom" title="{{ expertise|get_specialization_display }}">{{ expertise|get_specialization_code }}</div> {% endfor %} </td> + <td>{{ potfel.college }}</td> <td style="color: #ffffff; background-color:{{ potfel.status|potfelstatuscolor }};">{{ potfel.get_status_display }}<br/><small>{% voting_results_display potfel %}</small></td> <td>{{ potfel.latest_event_details }}</td> </tr> -- GitLab