1

One of the fields in my form should display a static currency symbol as the first character in the field. This character should not be able to be deleted from the field. I understand that I can use <span> elements to insert the symbol into the field.

The Problem

I don't know how to put <span> tags around my form fields. Currently, this part of the site looks like the following:

forms.py

class JobForm(forms.ModelForm):
class Meta:
    model = Job
    fields = [
        'Date',
        'Time_Start',
        'Time_End',
        'Employee',
        'Client',
        'Service',
        'Price',
    ]

views.py

def jobs_add(request):
    if request.method == "POST":
        form = JobForm(request.POST)
        if form.is_valid():
            form = JobForm(request.POST)
            form.save()
            return HttpResponseRedirect(reverse('jobs'))
    else:
        form = JobForm()
    return render(request, 'home/jobs_edit.html', {'form': form, 'new_job': True})

page.html

{% block content %}

<form method="POST">
    {% if new_job %}
        <h1>You are adding a new job</h1>
    {% else %}
        <h1>You are editing the details for job # {{ Job.Job_ID }}</h1>
    {% endif %}

    {% csrf_token %}

    {% form.as_ul %}

    <input type="submit" value="Save" />

    {% if new_job %}

    {% else %}
    <input type="submit" name="delete" value="Delete" />
    {% endif %}
</form>
{% endblock %}

1 Answer 1

1

We can do that by rendering fields manually. We don’t have to let Django unpack the form’s fields; we can do it manually as we like .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.