Skip to content

Commit

Permalink
Creates ProjectArea model (#1528)
Browse files Browse the repository at this point in the history
* creates projectarea model
  • Loading branch information
george-silva authored May 24, 2024
1 parent e4133d7 commit aa0a99b
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ docker-shell:

docker-makemigrations:
./src/planscape/bin/run.sh python manage.py makemigrations --no-header $(APP_LABEL) $(OPTIONS)
sudo chown -R $(USER): **/migrations
find . -type d -name migrations -exec sudo chown -R $(USER): {} +

docker-migrate:
./src/planscape/bin/run.sh python manage.py migrate
Expand Down
77 changes: 77 additions & 0 deletions src/planscape/planning/migrations/0018_projectarea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from django.conf import settings
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("planning", "0017_userprefs"),
]

operations = [
migrations.CreateModel(
name="ProjectArea",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True, null=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"deleted_at",
models.DateTimeField(
help_text="Define if the entity has been deleted or not and when",
null=True,
verbose_name="Deleted at",
),
),
("uuid", models.UUIDField(db_index=True, default=uuid.uuid4)),
("name", models.CharField(max_length=128)),
(
"origin",
models.CharField(
choices=[
("OPTIMIZATION", "Optimization"),
("USER_CREATED", "User Created"),
],
default="OPTIMIZATION",
help_text="Determines where this project area came from.",
),
),
("data", models.JSONField(null=True)),
(
"geometry",
django.contrib.gis.db.models.fields.MultiPolygonField(srid=4269),
),
(
"created_by",
models.ForeignKey(
on_delete=django.db.models.deletion.RESTRICT,
related_name="project_areas",
to=settings.AUTH_USER_MODEL,
),
),
(
"scenario",
models.ForeignKey(
on_delete=django.db.models.deletion.RESTRICT,
related_name="project_areas",
to="planning.scenario",
),
),
],
options={
"verbose_name": "Project Area",
"verbose_name_plural": "Project Areas",
},
),
]
43 changes: 42 additions & 1 deletion src/planscape/planning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db.models import Q
from utils.uuid_utils import generate_short_uuid
from collaboration.models import UserObjectRole
from core.models import CreatedAtMixin, UpdatedAtMixin
from core.models import CreatedAtMixin, UpdatedAtMixin, DeletedAtMixin, UUIDMixin
import uuid

User = get_user_model()
Expand Down Expand Up @@ -229,3 +229,44 @@ class Meta:
class UserPrefs(CreatedAtMixin, UpdatedAtMixin, models.Model):
user = models.OneToOneField("auth.User", on_delete=models.CASCADE)
preferences = models.JSONField(blank=True, null=True)


class ProjectAreaOrigin(models.TextChoices):
# project comes from optimization algorithm, such as forsys
OPTIMIZATION = "OPTIMIZATION", "Optimization"
# project comes from direct user creation / import
USER_CREATED = "USER_CREATED", "User Created"


class ProjectArea(
UUIDMixin, CreatedAtMixin, UpdatedAtMixin, DeletedAtMixin, models.Model
):
created_by = models.ForeignKey(
User,
related_name="project_areas",
on_delete=models.RESTRICT,
)

scenario = models.ForeignKey(
Scenario,
related_name="project_areas",
on_delete=models.RESTRICT,
)

name = models.CharField(max_length=128)

origin = models.CharField(
choices=ProjectAreaOrigin.choices,
default=ProjectAreaOrigin.OPTIMIZATION,
help_text="Determines where this project area came from.",
)

data = models.JSONField(null=True)

geometry = models.MultiPolygonField(
srid=settings.CRS_INTERNAL_REPRESENTATION,
)

class Meta:
verbose_name = "Project Area"
verbose_name_plural = "Project Areas"

0 comments on commit aa0a99b

Please sign in to comment.