Checklist
Is your feature related to a problem? Please describe.
I want to mark some relative fields so that they don't appear as links in the UI.
For example, I have User and Address models (some unnecessary details of the description of sqlalchemy models was omitted):
class Address:
id: int
zip_code: int
city: str
street: str
house_number: str
def __repr__(self):
return f"{self.zip_code}, {self.city}, {self.street}, {self.house_number}"
class User:
id: int
name: str
age: int
address: Address
Also I want create only UserAdmin model
class UserAdmin(ModelView, model=User):
name = "User"
name_plural = "Users"
column_list = ["id", "name"]
On User`s details page I will see the address field as a link leading to an 404 page (because I didn't create AddressAdmin model).
I want to mark address field as a simple text, without any links
Describe the solution you would like.
Add new ModelView attribute, called excluded_relations_names (for example)
class UserAdmin(ModelView, model=User):
name = "User"
name_plural = "Users"
column_list = ["id", "name"]
excluded_relations_names = ["address"]
add some conditions in details.html
...
<tr>
<td>{{ label }}</td>
{% set value, formatted_value = model_view.get_detail_value(model, name) %}
{% if name in model_view._relation_names %}
{% if is_list( value ) %}
<td>
{% for elem, formatted_elem in zip(value, formatted_value) %}
<a href="{{ model_view._build_url_for('admin:details', request, elem) }}">({{ formatted_elem }})</a>
{% endfor %}
</td>
{% else %}
{% if name in model_view.excluded_relations_names %} <!-- NEW CHECKS HERE -->
<td>{{ formatted_value }}</td>
{% else%}
<td><a href="{{ model_view._url_for_details_with_prop(request, model, name) }}">{{ formatted_value }}</a>
</td>
{% endif %}
{% endif %}
{% else %}
<td>{{ formatted_value }}</td>
{% endif %}
</tr>
...
Describe alternatives you considered
I found one way to show field as a normal text, without any links:
- Add some custom field to column_details_list
- Bind this field to related model
- Create a label for this custom field
class UserAdmin(ModelView, model=User):
name = "User"
name_plural = "Users"
column_list = ["id", "name"]
column_details_list = [
"id",
"name",
"age",
"address_field" # some custom field name
]
column_formatters_detail = {
"address_field": lambda m, a: m.address
}
column_labels = {
"address_field": "address"
}
What if you have much more fields in UserModel? If you want add a custom field to column_details_list, you should explicitly specify all other fields.
Looks like a long workaround.
Additional context
No response
Checklist
Is your feature related to a problem? Please describe.
I want to mark some relative fields so that they don't appear as links in the UI.
For example, I have User and Address models (some unnecessary details of the description of sqlalchemy models was omitted):
Also I want create only UserAdmin model
On User`s details page I will see the address field as a link leading to an 404 page (because I didn't create AddressAdmin model).
I want to mark address field as a simple text, without any links
Describe the solution you would like.
Add new ModelView attribute, called
excluded_relations_names(for example)add some conditions in details.html
Describe alternatives you considered
I found one way to show field as a normal text, without any links:
What if you have much more fields in UserModel? If you want add a custom field to column_details_list, you should explicitly specify all other fields.
Looks like a long workaround.
Additional context
No response