I created a model called worker that has a field called signature where I'm uploading the signature digital in an image:
class Trabajador(models.Model):
usuario = models.OneToOneField(User)
dni = models.CharField(max_length=8,primary_key=True)
apellido_paterno = models.CharField(max_length=50)
apellido_materno = models.CharField(max_length=50)
nombres = models.CharField(max_length=100)
firma = models.ImageField(upload_to='firmas')
estado = models.BooleanField(default=True)
def nombre_completo(self):
return self.apellido_paterno+' '+self.apellido_materno+' '+self.nombres
def __str__(self):
return smart_str(self.apellido_paterno)+' '+smart_str(self.apellido_materno)+' '+smart_str(self.nombres)
I have a form named TrabajadorForm where I use the model created previously:
class TrabajadorForm(forms.ModelForm):
class Meta:
model = Trabajador
fields =['dni','apellido_paterno','apellido_materno','nombres','usuario','firma']
def __init__(self, *args, **kwargs):
super(TrabajadorForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
self.fields[field].widget.attrs.update({
'class': 'form-control'
})
I have a view to be able to modify the worker:
class ModificarTrabajador(UpdateView):
model = Trabajador
template_name = 'modificar_trabajador.html'
form_class = TrabajadorForm
success_url = reverse_lazy('administracion:maestro_trabajadores')
And the template called modify_worker:
{% extends "base_administracion.html" %}
{% block cuerpo %}
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Modificar Trabajador</h1>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Por favor ingrese todos los campos necesarios.
</div>
<div class="panel-body">
<form role="form" action="{% url 'administracion:modificar_trabajador' trabajador.pk %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
{{ form.as_p }}
</div>
<div class='form-group'>
<input type="submit" class="btn btn-primary" name="submit" value="Modificar Trabajador">
<button type="reset" class="btn btn-primary" onclick="location.href='{% url 'administracion:maestro_trabajadores' %}'">
Cancelar
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="popup"></div>
{% endblock cuerpo %}
Until then everything works very well but when I click on the signature link I get an error because the link points to:
and not to the correct location of the file, I would like to see if something can be done to solve this problem. Greetings.