From da7e15ff3f2a011a15b1fb4062bd8376f3caa69a Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sun, 6 Sep 2020 09:25:06 +0200 Subject: [PATCH] Add fields college and specialties to Journal --- .../migrations/0092_auto_20200906_0903.py | 26 ++++++++++++++++++ journals/migrations/0093_journal_college.py | 27 +++++++++++++++++++ journals/models/journal.py | 26 +++++++++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 journals/migrations/0092_auto_20200906_0903.py create mode 100644 journals/migrations/0093_journal_college.py diff --git a/journals/migrations/0092_auto_20200906_0903.py b/journals/migrations/0092_auto_20200906_0903.py new file mode 100644 index 000000000..8736d9d8c --- /dev/null +++ b/journals/migrations/0092_auto_20200906_0903.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.11 on 2020-09-06 07:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('colleges', '0016_populate_colleges'), + ('ontology', '0007_Branch_Field_Specialty'), + ('journals', '0091_auto_20200821_1427'), + ] + + operations = [ + migrations.AddField( + model_name='journal', + name='college', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='journals', to='colleges.College'), + ), + migrations.AddField( + model_name='journal', + name='specialties', + field=models.ManyToManyField(blank=True, related_name='journals', to='ontology.Specialty'), + ), + ] diff --git a/journals/migrations/0093_journal_college.py b/journals/migrations/0093_journal_college.py new file mode 100644 index 000000000..12c1526aa --- /dev/null +++ b/journals/migrations/0093_journal_college.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.11 on 2020-09-06 07:03 + +from django.db import migrations + + +def populate_journal_college(apps, schema_editor): + College = apps.get_model('colleges.College') + Journal = apps.get_model('journals.Journal') + + for journal in Journal.objects.all(): + field_name = journal.name.split(' ')[1] + if field_name != 'Selections': + college = College.objects.get(name=field_name) + journal.college = college + journal.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0092_auto_20200906_0903'), + ] + + operations = [ + migrations.RunPython(populate_journal_college, + reverse_code=migrations.RunPython.noop), + ] diff --git a/journals/models/journal.py b/journals/models/journal.py index 8b2cea9c9..493731e66 100644 --- a/journals/models/journal.py +++ b/journals/models/journal.py @@ -21,11 +21,35 @@ def cost_default_value(): class Journal(models.Model): - """Journal is a container of Publications with a unique issn and doi_label. + """Journal is a container of Publications, with a unique issn and doi_label. Publications may be categorized into issues or issues and volumes. + + Each Journal falls under the auspices of a specific College, which is ForeignKeyed. + The only exception is Selections, which does not point to any College + (in fact: it falls under the auspices of all colleges at the same time). + + A Journal's AcademicField is indirectly specified via the College, since + College has a ForeignKey to AcademicField. + + Specialties can optionally be specified (and should be consistent with the + College's `acad_field`). If none are given, the Journal operates field-wide. """ + college = models.ForeignKey( + 'colleges.College', + on_delete=models.PROTECT, + related_name='journals', + blank=True, null=True + ) + + specialties = models.ManyToManyField( + 'ontology.Specialty', + blank=True, + related_name='journals' + ) + + # TODO: remove discipline discipline = models.CharField(max_length=20, choices=SCIPOST_DISCIPLINES, default='physics') name = models.CharField(max_length=256, unique=True) name_abbrev = models.CharField(max_length=128, default='SciPost [abbrev]', -- GitLab