Skip to content

Commit 1df7128

Browse files
committed
WIP - Admin can add sections and fields for a model
1 parent ccde9e7 commit 1df7128

31 files changed

+586
-314
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.forms import ModelForm
2+
from cal_bc.projects.models.model_section import ModelSection
3+
from django.utils.translation import gettext as _
4+
5+
6+
class ModelSectionForm(ModelForm):
7+
class Meta:
8+
model = ModelSection
9+
fields = ["section_fields"]
10+
11+
def get_labels(self) -> dict[str, str]:
12+
return {"section_fields": _(self.object.name)}

src/cal_bc/projects/forms/project.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,11 @@ class Meta:
1616
fields = [
1717
"name",
1818
"district",
19-
"type",
20-
"location",
21-
"construction_period_length",
22-
"data_direction",
23-
"peak_periods_length",
19+
"model",
2420
]
2521

2622
labels = {
2723
"name": _("Project Name"),
28-
"type": _("Project Type"),
29-
"location": _("Project Location"),
30-
"construction_period_length": _("Length of Construction Period"),
31-
"data_direction": _("One- or Two-Way Data"),
32-
"peak_periods_length": _("Length of Peak Period(s) (up to 24 hrs)"),
33-
}
34-
35-
help_texts = {
36-
"construction_period_length": _("years"),
37-
"peak_periods_length": _("hours"),
24+
"model": _("Model"),
25+
"district": _("District"),
3826
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.forms import ModelForm
2+
from cal_bc.projects.models.project import Project
3+
from cal_bc.projects.models.project_field import ProjectField
4+
from django.utils.translation import gettext as _
5+
6+
7+
class ProjectFieldForm(ModelForm):
8+
class Meta:
9+
model = ProjectField
10+
fields = ["value", "project"]
11+
labels = {"value": _("Value")}
12+
widgets = {"project": Hidden()}
13+
14+
def get_labels(self) -> dict[str, str]:
15+
return {"value": _(self.object.model_section_field.name)}
16+
17+
18+
ProjectFieldFormset = inlineformset_factory(
19+
ModelSectionField,
20+
ProjectField,
21+
form=ProjectFieldForm,
22+
allow_create=False
23+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 5.2.7 on 2025-10-11 00:25
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
initial = True
8+
9+
dependencies = []
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name='Model',
14+
fields=[
15+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
16+
('name', models.CharField(null=False)),
17+
('url', models.CharField(null=False)),
18+
],
19+
),
20+
]

src/cal_bc/projects/migrations/0001_initial.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
# Generated by Django 5.2.7 on 2025-10-11 00:34
1+
# Generated by Django 5.2.7 on 2025-10-18 19:46
22

3+
import django.db.models.deletion
34
from django.db import migrations, models
45

56

67
class Migration(migrations.Migration):
78
dependencies = [
8-
("projects", "0001_initial"),
9+
('projects', '0001_create_models'),
910
]
1011

1112
operations = [
1213
migrations.CreateModel(
13-
name="Project",
14+
name='Project',
1415
fields=[
15-
(
16-
"id",
17-
models.BigAutoField(
18-
auto_created=True,
19-
primary_key=True,
20-
serialize=False,
21-
verbose_name="ID",
22-
),
23-
),
24-
("name", models.CharField()),
16+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17+
('name', models.CharField(null=False)),
18+
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.model', null=False)),
2519
],
2620
),
2721
]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 5.2.7 on 2025-10-15 22:42
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("projects", "0002_create_projects"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="project",
14+
name="district",
15+
field=models.IntegerField(
16+
choices=[
17+
(1, "District 1 - Eureka"),
18+
(2, "District 2 - Redding"),
19+
(3, "District 3 - Marysville / Sacramento"),
20+
(4, "District 4 - Bay Area / Oakland"),
21+
(5, "District 5 - Central Coast"),
22+
(6, "District 6 - Fresno / Bakersfield"),
23+
(7, "District 7 - Los Angeles / Ventura"),
24+
(8, "District 8 - San Bernardino / Riverside"),
25+
(9, "District 9 - Bishop"),
26+
(10, "District 10 - Stockton"),
27+
(11, "District 11 - San Diego"),
28+
(12, "District 12 - Orange County"),
29+
],
30+
null=False,
31+
),
32+
),
33+
]

src/cal_bc/projects/migrations/0003_project_construction_period_length_and_more.py

Lines changed: 0 additions & 133 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 5.2.7 on 2025-10-18 20:18
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('projects', '0003_add_project_district'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='ModelSection',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(null=False)),
19+
('help_text', models.CharField(null=False)),
20+
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.model', null=False)),
21+
],
22+
),
23+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 5.2.7 on 2025-10-18 23:24
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('projects', '0004_create_model_section'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='ModelSectionField',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(null=False)),
19+
('cell', models.CharField(null=False)),
20+
('help_text', models.CharField(null=False)),
21+
('model_section', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.modelsection', null=False)),
22+
],
23+
)
24+
]

0 commit comments

Comments
 (0)