Add school class to portfolio project
This commit is contained in:
parent
0e1764f51c
commit
f9273f745c
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.22 on 2021-08-10 13:47
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0027_auto_20210414_2116'),
|
||||
('portfolio', '0004_projectentry_document_url'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='project',
|
||||
name='school_class',
|
||||
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='users.SchoolClass'),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 2.2.22 on 2021-08-10 13:48
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def set_default_school_class(apps, schema_editor):
|
||||
Project = apps.get_model('portfolio', 'Project')
|
||||
projects = Project.objects.all()
|
||||
bulk_projects = []
|
||||
for project in projects:
|
||||
owner = project.student
|
||||
selected_class = owner.selected_class
|
||||
if selected_class is not None:
|
||||
project.school_class = selected_class
|
||||
bulk_projects.append(project)
|
||||
Project.objects.bulk_update(bulk_projects, ['school_class'])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('portfolio', '0005_project_school_class'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(set_default_school_class, migrations.RunPython.noop)
|
||||
]
|
||||
|
|
@ -8,6 +8,7 @@ class Project(TitleSlugDescriptionModel):
|
|||
appearance = models.CharField(blank=True, null=False, max_length=255)
|
||||
student = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='projects')
|
||||
final = models.BooleanField(default=False)
|
||||
school_class = models.ForeignKey('users.SchoolClass', null=True, default=None, on_delete=models.SET_NULL)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
|
|
|||
Loading…
Reference in New Issue