Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get first parent pictogram if not defined #51

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/project/api/serializers/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


class ObservationCategorySerializer(serializers.ModelSerializer):
pictogram = serializers.FileField(source="inherited_pictogram", read_only=True)

class Meta:
model = ObservationCategory
Expand Down
8 changes: 8 additions & 0 deletions backend/project/observations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
def children(self):
return self.get_children()

@property
def inherited_pictogram(self):
"""Return parent pictogram if current pictogram is empty."""
if not self.pictogram:
parent = self.get_ancestors().filter(pictogram__isnull=False).last()
return parent.pictogram if parent else None
return self.pictogram

Check warning on line 49 in backend/project/observations/models.py

View check run for this annotation

Codecov / codecov/patch

backend/project/observations/models.py#L49

Added line #L49 was not covered by tests

class Meta:
verbose_name = _("Category")
verbose_name_plural = _("Categories")
Expand Down
12 changes: 10 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
CHANGE LOG
==========

1.0.12+dev
----------

**Improvements**

- Category now return first parent pictogram available if not defined


1.0.2 (2024-07-24)
----------------------
---------------------

**Bugfix**

Expand All @@ -14,7 +22,7 @@ CHANGE LOG
- improve UI

1.0.1 (2024-07-24)
----------------------
---------------------

**Improvements**

Expand Down