diff --git a/journals/migrations/0092_auto_20200906_0903.py b/journals/migrations/0092_auto_20200906_0903.py new file mode 100644 index 0000000000000000000000000000000000000000..8736d9d8c604d5a4d9cabdb1fee05a740824ca70 --- /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 0000000000000000000000000000000000000000..12c1526aa25f98af3e02605fd1d2bd9b3b8eaee4 --- /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 8b2cea9c9b0b0587513e6ebccadc58c7053675e9..493731e664b84ac8d06feac6ab6ea758e50d4dab 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]',