From cd605a5136b0f36835ca42d301b9f0ca5d2562e7 Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Wed, 20 Mar 2024 13:11:00 +0200 Subject: [PATCH 1/5] Add Project.subjects --- app/general/migrations/0001_initial.py | 3 ++- app/general/models.py | 1 + app/general/tests/tests_language.py | 1 - app/general/tests/tests_projects.py | 8 +++++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/general/migrations/0001_initial.py b/app/general/migrations/0001_initial.py index 0be9c218..988c857c 100644 --- a/app/general/migrations/0001_initial.py +++ b/app/general/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.2 on 2024-03-19 08:51 +# Generated by Django 5.0.2 on 2024-03-20 08:58 import django.db.models.deletion from django.db import migrations, models @@ -48,6 +48,7 @@ class Migration(migrations.Migration): ('start_date', models.DateField(blank=True, null=True)), ('end_date', models.DateField(blank=True, null=True)), ('Institution', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='general.institution', verbose_name='institution')), + ('subjects', models.ManyToManyField(to='general.subject', blank=True)), ], ), ] diff --git a/app/general/models.py b/app/general/models.py index 822cb0ff..59118b89 100644 --- a/app/general/models.py +++ b/app/general/models.py @@ -10,6 +10,7 @@ class Project(models.Model): Institution = models.ForeignKey( "Institution", on_delete=models.CASCADE, blank=True, verbose_name=("institution") ) + subjects = models.ManyToManyField("Subject", blank=True) def __str__(self): return self.name diff --git a/app/general/tests/tests_language.py b/app/general/tests/tests_language.py index 36a9882b..2efe19bc 100644 --- a/app/general/tests/tests_language.py +++ b/app/general/tests/tests_language.py @@ -7,7 +7,6 @@ class TestSubject(TestCase): def setUp(self): - # pass self.subject = Subject.objects.create(name="Maths") self.subject2 = Subject.objects.create(name="Science") diff --git a/app/general/tests/tests_projects.py b/app/general/tests/tests_projects.py index e89b2122..abf0b5bb 100644 --- a/app/general/tests/tests_projects.py +++ b/app/general/tests/tests_projects.py @@ -3,12 +3,13 @@ from django.test import TestCase -from general.models import Institution, Project +from general.models import Institution, Project, Subject class TestProjects(TestCase): def setUp(self): self.institution = Institution.objects.create(name="Test Institution") + self.subject = Subject.objects.create(name="Test Subject") self.project = Project.objects.create( name="Test Project", url="http://test.com", @@ -17,6 +18,7 @@ def setUp(self): end_date="2023-12-31", Institution=self.institution, ) + self.project.subjects.add(self.subject) def test_project_creation(self): self.assertTrue(isinstance(self.project, Project)) @@ -27,6 +29,7 @@ def test_project_creation(self): self.assertEqual(self.project.start_date, "2023-01-01") self.assertEqual(self.project.end_date, "2023-12-31") self.assertEqual(self.project.Institution, self.institution) + self.assertIn(self.subject, self.project.subjects.all()) def test_project_name(self): self.assertEqual(self.project.name, "Test Project") @@ -47,6 +50,9 @@ def test_project_end_date(self): def test_project_institution(self): self.assertEqual(self.project.Institution.name, "Test Institution") + def test_project_subject(self): + self.assertTrue(self.project.subjects.filter(name="Test Subject").exists()) + def test_str(self): self.assertEqual(str(self.project), "Test Project") From 76ef9d8b48cefb832420d78a37e32772ef481685 Mon Sep 17 00:00:00 2001 From: Friedel Wolff Date: Wed, 3 Apr 2024 14:35:00 +0200 Subject: [PATCH 2/5] make: +dev-quick-install --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index abd67139..40a2be82 100644 --- a/Makefile +++ b/Makefile @@ -95,3 +95,10 @@ load-fixtures: pre-commit-install: clear pre-commit install + +dev-quick-install: + clear + @make migrate + @make load-fixtures + echo "Creating superuser" + @make create-super-user From d31a1299986d9c5943a06408c5b0ab07ed2d5689 Mon Sep 17 00:00:00 2001 From: Friedel Wolff Date: Wed, 3 Apr 2024 14:37:15 +0200 Subject: [PATCH 3/5] Rename Project.Institution -> Project.institution --- app/fixtures/projects.json | 4 ++-- app/general/migrations/0001_initial.py | 4 ++-- app/general/models.py | 4 ++-- app/general/tests/tests_projects.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/fixtures/projects.json b/app/fixtures/projects.json index a6de4fbb..6c85eb2b 100644 --- a/app/fixtures/projects.json +++ b/app/fixtures/projects.json @@ -8,7 +8,7 @@ "logo": "logo.png", "start_date": "2020-01-01", "end_date": "2020-01-01", - "Institution": 1 + "institution": 1 } }, { @@ -20,7 +20,7 @@ "logo": "logo.png", "start_date": "2020-01-01", "end_date": "2020-01-01", - "Institution": 2 + "institution": 2 } } ] diff --git a/app/general/migrations/0001_initial.py b/app/general/migrations/0001_initial.py index 988c857c..43eb1dbd 100644 --- a/app/general/migrations/0001_initial.py +++ b/app/general/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.2 on 2024-03-20 08:58 +# Generated by Django 5.0.2 on 2024-04-03 09:12 import django.db.models.deletion from django.db import migrations, models @@ -47,7 +47,7 @@ class Migration(migrations.Migration): ('logo', models.FileField(blank=True, upload_to='logos/')), ('start_date', models.DateField(blank=True, null=True)), ('end_date', models.DateField(blank=True, null=True)), - ('Institution', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='general.institution', verbose_name='institution')), + ('institution', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='general.institution', verbose_name='institution')), ('subjects', models.ManyToManyField(to='general.subject', blank=True)), ], ), diff --git a/app/general/models.py b/app/general/models.py index 59118b89..1475f235 100644 --- a/app/general/models.py +++ b/app/general/models.py @@ -7,8 +7,8 @@ class Project(models.Model): logo = models.FileField(upload_to="logos/", blank=True) start_date = models.DateField(blank=True, null=True) end_date = models.DateField(blank=True, null=True) - Institution = models.ForeignKey( - "Institution", on_delete=models.CASCADE, blank=True, verbose_name=("institution") + institution = models.ForeignKey( + "Institution", on_delete=models.CASCADE, blank=True, verbose_name="institution" ) subjects = models.ManyToManyField("Subject", blank=True) diff --git a/app/general/tests/tests_projects.py b/app/general/tests/tests_projects.py index abf0b5bb..3baf88bb 100644 --- a/app/general/tests/tests_projects.py +++ b/app/general/tests/tests_projects.py @@ -16,7 +16,7 @@ def setUp(self): logo="http://test.com/logo.png", start_date="2023-01-01", end_date="2023-12-31", - Institution=self.institution, + institution=self.institution, ) self.project.subjects.add(self.subject) @@ -28,7 +28,7 @@ def test_project_creation(self): self.assertEqual(self.project.logo, "http://test.com/logo.png") self.assertEqual(self.project.start_date, "2023-01-01") self.assertEqual(self.project.end_date, "2023-12-31") - self.assertEqual(self.project.Institution, self.institution) + self.assertEqual(self.project.institution, self.institution) self.assertIn(self.subject, self.project.subjects.all()) def test_project_name(self): @@ -48,7 +48,7 @@ def test_project_end_date(self): self.assertEqual(end_date.strftime(date_format), "2023-12-31") def test_project_institution(self): - self.assertEqual(self.project.Institution.name, "Test Institution") + self.assertEqual(self.project.institution.name, "Test Institution") def test_project_subject(self): self.assertTrue(self.project.subjects.filter(name="Test Subject").exists()) From 31eb366fc1d7fdd6abf3059e0af5a34d81f4bee8 Mon Sep 17 00:00:00 2001 From: Friedel Wolff Date: Wed, 3 Apr 2024 14:53:30 +0200 Subject: [PATCH 4/5] Remove whitespace at the end of .gitignore --- .gitignore | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index bf9603d7..47866af8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,3 @@ venv/ ENV/ env.bak/ venv.bak/ - - - - - - From d9c75ca3665fc09b48f2fc1efb5466414660bdeb Mon Sep 17 00:00:00 2001 From: Friedel Wolff Date: Wed, 3 Apr 2024 14:54:14 +0200 Subject: [PATCH 5/5] Increase some field max_lengths --- app/general/migrations/0001_initial.py | 6 +++--- app/general/models.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/general/migrations/0001_initial.py b/app/general/migrations/0001_initial.py index 43eb1dbd..66665c47 100644 --- a/app/general/migrations/0001_initial.py +++ b/app/general/migrations/0001_initial.py @@ -27,15 +27,15 @@ class Migration(migrations.Migration): name='Language', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100, unique=True)), - ('iso_code', models.CharField(help_text='Enter the ISO code for the language', max_length=10, unique=True)), + ('name', models.CharField(max_length=150, unique=True)), + ('iso_code', models.CharField(help_text='Enter the ISO code for the language', max_length=50, unique=True)), ], ), migrations.CreateModel( name='Subject', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100, unique=True)), + ('name', models.CharField(max_length=150, unique=True)), ], ), migrations.CreateModel( diff --git a/app/general/models.py b/app/general/models.py index 1475f235..fb5ccfa6 100644 --- a/app/general/models.py +++ b/app/general/models.py @@ -28,9 +28,9 @@ def __str__(self): class Language(models.Model): - name = models.CharField(max_length=100, unique=True) + name = models.CharField(max_length=150, unique=True) iso_code = models.CharField( - max_length=10, unique=True, help_text="Enter the ISO code for the language" + max_length=50, unique=True, help_text="Enter the ISO code for the language" ) def __str__(self): @@ -38,7 +38,7 @@ def __str__(self): class Subject(models.Model): - name = models.CharField(max_length=100, unique=True) + name = models.CharField(max_length=150, unique=True) def __str__(self): return self.name