Skip to content

Commit

Permalink
Merge pull request #526 from oakdbca/main
Browse files Browse the repository at this point in the history
Latest Changes
  • Loading branch information
xzzy authored Sep 11, 2024
2 parents 7ccd752 + aa45c35 commit a44dfcd
Show file tree
Hide file tree
Showing 23 changed files with 984 additions and 661 deletions.
33 changes: 26 additions & 7 deletions boranga/components/main/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,22 @@ def get_model_fields(self, obj):
if not obj.model_class():
return []
fields = obj.model_class()._meta.get_fields()
exclude_fields = []
if hasattr(obj.model_class(), "BULK_IMPORT_EXCLUDE_FIELDS"):
exclude_fields = obj.model_class().BULK_IMPORT_EXCLUDE_FIELDS

def filter_fields(field):
return not field.auto_created and not (
field.is_relation
and type(field)
not in [
ForeignKey,
OneToOneField,
]
return (
field.name not in exclude_fields
and not field.auto_created
and not (
field.is_relation
and type(field)
not in [
ForeignKey,
OneToOneField,
]
)
)

fields = list(filter(filter_fields, fields))
Expand All @@ -163,6 +170,17 @@ def filter_fields(field):
xlsx_validation_type = get_openpyxl_data_validation_type_for_django_field(
field
)
lookup_field_options = None
if hasattr(field, "related_model") and field.related_model:
related_model = field.related_model
fields = related_model._meta.get_fields()
lookup_field_options = [
field.verbose_name.lower()
for field in related_model._meta.get_fields()
if not field.related_model
and field.unique
and not field.name.endswith("_number")
]
model_fields.append(
{
"name": field.name,
Expand All @@ -172,6 +190,7 @@ def filter_fields(field):
"allow_null": allow_null,
"max_length": max_length,
"xlsx_validation_type": xlsx_validation_type,
"lookup_field_options": lookup_field_options,
}
)
return model_fields
6 changes: 1 addition & 5 deletions boranga/components/occurrence/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class OccurrenceReportGeometryInline(admin.StackedInline):
"area_sqhm",
),
(
"intersects",
"locked",
"show_on_map",
),
Expand Down Expand Up @@ -222,10 +221,7 @@ class OccurrenceGeometryInline(nested_admin.NestedStackedInline):
"area_sqm",
"area_sqhm",
),
(
"intersects",
"locked",
),
("locked",),
(
"created_date",
"updated_date",
Expand Down
Loading

0 comments on commit a44dfcd

Please sign in to comment.