-
-
Notifications
You must be signed in to change notification settings - Fork 53
Current value doesn't show up [in edit] #130
Replies: 3 comments · 5 replies
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @domdinicola, Thank you for reaching out. Since this is a tested core functionality, I can safely say it should work. However, it doesn't seem to be working for you. The screenshot is a good start, but I would need some code examples to understand what's wrong. Best Joe |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks for the quick answer @codingjoe ! Absolutely.. this should be straighforward! Widget from django_select2 import forms as s2forms
from logistica.apps.rutas.models import Lugar, Ciudad
class CiudadWidget(s2forms.ModelSelect2Widget):
model = Ciudad
search_fields = [
"nombre__icontains",
]
class LugarWidget(s2forms.ModelSelect2Widget):
model = Lugar
search_fields = [
"codigo__icontains",
"lugar__icontains",
"ciudad__nombre__icontains"
] view class LiquidacionEgresosListView(FilterView, ListView):
model = models.LiquidacionEgresos
filterset_fields = ['numero', 'socio', ]
def get_form(self, form_class=None):
form = super().get_form(form_class)
form.fields['socio'].widget = SocioWidget()
return form HTML {% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LEB</title>
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'tailwind.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'leb.css' %}">
{% endblock css %}
{% block js %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
{% endblock js %}
</head>
<body>
<form method="post">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input
class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold my-5 py-1 px-2 rounded focus:outline-none focus:shadow-outline"
type="submit" value="Actualizar">
</form>
</body>
</html> I reduced the HTML to minimum (removing all the extends) but still it doesn't work.. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @domdinicola, I think I wasn't clear. I need the HTML that you see in your browser, not the Django template. Best, Joe |
Beta Was this translation helpful? Give feedback.
All reactions
-
@codingjoe there you go! Thanks!
|
Beta Was this translation helpful? Give feedback.
All reactions
-
@codingjoe any chance you can have a look? Thank you! |
Beta Was this translation helpful? Give feedback.
All reactions
-
looks like I have this issue when I use filterset fields and changing the widget through the get_form. if I create a proper form class everything works fine. |
Beta Was this translation helpful? Give feedback.
All reactions
-
@codingjoe looks like the issue is when this is applied when working with django-filters and setting the widget in the get_form method |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
This discussion was converted from issue #129 on March 21, 2022 14:37.
-
Goal
Make select2 work in edit mode
Problem
when editing an instance the current value is not showing up (it starts empty) although the value is there (see snipet). Everything else is working file.
Code Snippet
(Pdb++) form['origen']
<django.forms.boundfield.BoundField object at 0x7f9adabf77f0>
(Pdb++) form['origen'].initial
50
Thanks in advance and feel free to ask more info.
Dom
Beta Was this translation helpful? Give feedback.
All reactions