Skip to content

Commit c204003

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

31 files changed

+655
-303
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.forms import ModelForm
2+
from cal_bc.projects.models.project_field import ProjectField
3+
from django.utils.translation import gettext as _
4+
5+
6+
class ProjectFieldForm(ModelForm):
7+
class Meta:
8+
model = ProjectField
9+
fields = ["value", "project"]
10+
labels = {"value": _("Value")}
11+
widgets = {"project": Hidden()}
12+
13+
def get_labels(self) -> dict[str, str]:
14+
return {"value": _(self.object.model_section_field.name)}
15+
16+
17+
ProjectFieldFormset = inlineformset_factory(
18+
ModelSectionField, ProjectField, form=ProjectFieldForm, allow_create=False
19+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
(
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(null=False)),
25+
("url", models.CharField(null=False)),
26+
],
27+
),
28+
]

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/cal_bc/projects/migrations/0002_create_projects.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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 = [
@@ -21,7 +22,15 @@ class Migration(migrations.Migration):
2122
verbose_name="ID",
2223
),
2324
),
24-
("name", models.CharField()),
25+
("name", models.CharField(null=False)),
26+
(
27+
"model",
28+
models.ForeignKey(
29+
on_delete=django.db.models.deletion.CASCADE,
30+
to="projects.model",
31+
null=False,
32+
),
33+
),
2534
],
2635
),
2736
]
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
dependencies = [
9+
("projects", "0003_add_project_district"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="ModelSection",
15+
fields=[
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("name", models.CharField(null=False)),
26+
("help_text", models.CharField(null=False)),
27+
(
28+
"model",
29+
models.ForeignKey(
30+
on_delete=django.db.models.deletion.CASCADE,
31+
to="projects.model",
32+
null=False,
33+
),
34+
),
35+
],
36+
),
37+
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
dependencies = [
9+
("projects", "0004_create_model_section"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="ModelSectionField",
15+
fields=[
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("name", models.CharField(null=False)),
26+
("cell", models.CharField(null=False)),
27+
("help_text", models.CharField(null=False)),
28+
(
29+
"model_section",
30+
models.ForeignKey(
31+
on_delete=django.db.models.deletion.CASCADE,
32+
to="projects.modelsection",
33+
null=False,
34+
),
35+
),
36+
],
37+
)
38+
]

0 commit comments

Comments
 (0)