Skip to content

Commit

Permalink
fix details page breaking when file field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Oct 14, 2024
1 parent d4c863c commit d4c36ed
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/falco/management/commands/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.core.management.base import CommandError
from django.template import Context
from django.template import Template

from falco.management.base import CleanRepoOnlyCommand
from falco.management.commands.copy_template import get_template_absolute_path
from falco.utils import run_html_formatters
Expand Down Expand Up @@ -217,13 +218,20 @@ def get_model_dict(model) -> "DjangoModel":

verbose_name = model._meta.verbose_name # noqa
verbose_name_plural = model._meta.verbose_name_plural # noqa

def get_accessor(field) -> str:
base_accessor = f"{name_lower}.{field.name}"
if field.__class__.__name__ in file_fields:
return f"{{% if {base_accessor} %}} {{{{ {base_accessor}.url }}}} {{% endif %}}"
else:
return "{{" + base_accessor + "}}"

fields: dict[str, DjangoField] = {
field.name: {
"verbose_name": field.verbose_name,
"editable": field.editable,
"class_name": field.__class__.__name__,
"accessor": "{{"
f"{name_lower}.{field.name}" + (".url }}" if field.__class__.__name__ in file_fields else "}}"),
"accessor": get_accessor(field)
}
for field in model._meta.fields # noqa
if field.name not in excluded_fields
Expand Down

0 comments on commit d4c36ed

Please sign in to comment.