#112 WIP: Restructure CompensationAction
* changes action_type from ForeignKey into M2M * adds migration * changes form widget * WIP: changes rendering on detail view of compensation * TEST NOT CHECKED YET!
This commit is contained in:
@@ -10,9 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||
from compensation.managers import CompensationActionManager
|
||||
from konova.models import BaseResource
|
||||
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED
|
||||
|
||||
|
||||
class UnitChoices(models.TextChoices):
|
||||
@@ -31,10 +29,8 @@ class CompensationAction(BaseResource):
|
||||
"""
|
||||
Compensations include actions like planting trees, refreshing rivers and so on.
|
||||
"""
|
||||
action_type = models.ForeignKey(
|
||||
action_type = models.ManyToManyField(
|
||||
KonovaCode,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
limit_choices_to={
|
||||
"code_lists__in": [CODELIST_COMPENSATION_ACTION_ID],
|
||||
@@ -57,10 +53,8 @@ class CompensationAction(BaseResource):
|
||||
unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices)
|
||||
comment = models.TextField(blank=True, null=True, help_text="Additional comment")
|
||||
|
||||
objects = CompensationActionManager()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.action_type} | {self.amount} {self.unit}"
|
||||
return f"{self.action_type.all()} | {self.amount} {self.unit}"
|
||||
|
||||
@property
|
||||
def unit_humanize(self):
|
||||
|
||||
@@ -104,12 +104,12 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.get_created_action(user)
|
||||
comp_action = CompensationAction.objects.create(
|
||||
action_type=form_data["action_type"],
|
||||
amount=form_data["amount"],
|
||||
unit=form_data["unit"],
|
||||
comment=form_data["comment"],
|
||||
created=user_action,
|
||||
)
|
||||
comp_action.action_type.set(form_data.get("action_type", []))
|
||||
comp_action_details = form_data["action_type_details"]
|
||||
comp_action.action_type_details.set(comp_action_details)
|
||||
self.actions.add(comp_action)
|
||||
|
||||
Reference in New Issue
Block a user