Skip to content

Commit

Permalink
Merge pull request #2 from SADiLaR/feature/subject-update-cleaner
Browse files Browse the repository at this point in the history
Add Project.subjects
  • Loading branch information
daniel-gray-tangent authored Apr 4, 2024
2 parents dd20e96 + d9c75ca commit 65e5954
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,3 @@ venv/
ENV/
env.bak/
venv.bak/






7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/fixtures/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"logo": "logo.png",
"start_date": "2020-01-01",
"end_date": "2020-01-01",
"Institution": 1
"institution": 1
}
},
{
Expand All @@ -20,7 +20,7 @@
"logo": "logo.png",
"start_date": "2020-01-01",
"end_date": "2020-01-01",
"Institution": 2
"institution": 2
}
}
]
11 changes: 6 additions & 5 deletions app/general/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.2 on 2024-03-19 08:51
# Generated by Django 5.0.2 on 2024-04-03 09:12

import django.db.models.deletion
from django.db import migrations, models
Expand Down Expand Up @@ -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(
Expand All @@ -47,7 +47,8 @@ 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)),
],
),
]
11 changes: 6 additions & 5 deletions app/general/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ 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)

def __str__(self):
return self.name
Expand All @@ -27,17 +28,17 @@ 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):
return self.name


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
1 change: 0 additions & 1 deletion app/general/tests/tests_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
14 changes: 10 additions & 4 deletions app/general/tests/tests_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

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",
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)

def test_project_creation(self):
self.assertTrue(isinstance(self.project, Project))
Expand All @@ -26,7 +28,8 @@ 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):
self.assertEqual(self.project.name, "Test Project")
Expand All @@ -45,7 +48,10 @@ 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())

def test_str(self):
self.assertEqual(str(self.project), "Test Project")
Expand Down

0 comments on commit 65e5954

Please sign in to comment.