oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
425 stars 81 forks source link

Change foreign key fields link from update to detail page #71

Open daniellboy opened 6 years ago

daniellboy commented 6 years ago

I wanna ask about related fields in this cruds-template. By default, if we have a field from a model which is a foreign key, then, in the list and detail page it will show that field as a link and direct to update page of that foreign key model. I wanna change then the link to the detail page. How can i do that? The screenshoot like below. Look at the link at the bottom left. How can i redirect them to the detail page?

Thankyou image

oscarmlage commented 6 years ago

Talking about the list view you can create your own templates/crud/columns/foreignkey.html overriding the cruds_adminlte one and put there the related html you want to render.

About the detail page, IIRC, you need to create a custom widget (take a look to templates/widget/ directory) and define that FK-field as your widget in the related custom form:

class CustomForm(forms.ModelForm):
    class Meta:
        model = Yourmodel
        widgets = {
            'yourFKfield': CustomWidget,
            ...
        }
daniellboy commented 6 years ago

May i know how to overriding the templates/crud/columns/foreignkey.html from the cruds_adminlte and how to render it?

Thanks in advance

oscarmlage commented 6 years ago

Following the Django templates inheritance principle, if you have the directory crud/columns inside your TEMPLATES.DIRS in your project, Django will load it before the cruds_adminlte one.

Take a look to the Django oficial docs.

daniellboy commented 6 years ago

I got it. Then from this code in foreignkey.html, which part i should change so the link it would redirect to detail page and not update page?

{% load crud_tags %}

{% if object|format_value:field != null %}
    {{ object|format_value:field }}
{% else %}
    {{ nothing }}
{% endif %}
MFaulk13 commented 4 years ago

I guess you have to override format_value templatetag in crud_tags. I tried, but i couldn't get it working. Any suggestions? Also, is it possible to have the inline on the detail view instead of the update view?