I have these Models, Tipos, Prioridad and Estado, related to Tarea
as defined below:
class Tipos(models.Model):
tipo = models.CharField(max_length=16,
verbose_name='tipo')
abrv = models.CharField(max_length=4,
null=True,
blank=True,
default='')
class Meta:
verbose_name = "Tipo"
verbose_name_plural = "Tipos"
def __str__(self):
return self.tipo
class Prioridad(models.Model):
prioridad = models.CharField(max_length=16,
verbose_name='prioridad')
abrv = models.CharField(max_length=4,
null=True,
blank=True,
default='')
orden = models.IntegerField(u'orden', blank=False)
class Meta:
verbose_name = "Prioridad"
verbose_name_plural = "Prioridades"
def __str__(self):
return self.prioridad
class Estado(models.Model):
estado = models.CharField(max_length=16,
verbose_name='estado')
abrv = models.CharField(max_length=4,
null=True,
blank=True,
default='')
class Meta:
verbose_name = "Estado"
verbose_name_plural = "Estados"
def __str__(self):
return self.estado
class Tarea(models.Model):
numtar = models.AutoField(primary_key=True)
cliente = models.ForeignKey(User,
related_name='user_cliente',
null=True,
on_delete=models.DO_NOTHING)
apoyo = models.ForeignKey(User,
related_name='user_apoyo',
null=True,
on_delete=models.DO_NOTHING)
asignado = models.ForeignKey(User,
related_name='user_asignado',
null=True,
on_delete=models.DO_NOTHING)
descorta = models.CharField(max_length=140)
deslarga = models.TextField(max_length=8195)
estado = models.ForeignKey(Estado,
null=True,
on_delete=models.SET_NULL)
tipo = models.ForeignKey(Tipos,
null=True,
on_delete=models.SET_NULL)
prioridad = models.ForeignKey(Prioridad,
null=True,
on_delete=models.SET_NULL)
creacion = models.DateTimeField(auto_now_add=True)
revision = models.DateTimeField(auto_now=True, blank=True)
cierre = models.DateTimeField(null=True, blank=True)
class Meta:
verbose_name = "Tarea"
verbose_name_plural = "Tareas"
def __str__(self):
return '%s' % (str(self.numtar))
and I call the following view:
@login_required(login_url='/login')
def newincid_view(request):
perfil = ExUserProfile.objects.get(user=request.user)
prioridad_media = Prioridad.objects.get(prioridad='Media')
estado_abierta = Estado.objects.get(estado='Abierta')
tipo_incidencia = Tipos.objects.get(tipo='Incidencia')
datos_apertura = {'cliente': perfil.user,
'tipo': tipo_incidencia,
'prioridad:': prioridad_media,
'estado': estado_abierta
}
if request.method == 'POST':
form = newincidForm(request.POST,initial=datos_apertura)
if form.is_valid():
tar=form.save(commit=True)
apertura = TipoNota.objects.get(tiponota='Apertura')
anotacion = Nota(numtar=tar, tiponota=apertura,
anotador=perfil.user,
contenido='Incidencia Abierta')
anotacion.save()
else:
form = newincidForm(initial=datos_apertura)
return render(request, "incid/newincid.html", {'form':form})
with this form:
class newincidForm(ModelForm):
class Meta:
model = Tarea
exclude = ['numtar', 'creacion', 'revision', 'cierre']
def __init__(self, *args, **kwargs):
super(newincidForm, self).__init__(*args, **kwargs)
self.fields['descorta'].widget.attrs['class'] = 'form-control no-resize'
self.fields['deslarga'].widget.attrs['class'] = 'form-control no-resize autogrowth'
and this template:
{% extends "incid/base_incid.html" %}
{% load bootstrap3 %}
{% load static %}
{% load logo %}
{% load i18n %} <!-- Hooks para poder hacerlo multilingüe -->
{% load tags_html %}
{% block css %}
{% bootstrap_css %}
{% bootstrap_javascript %}
<link rel="stylesheet"
href="{% static 'adminbsb/plugins/jquery-datatable/skin/bootstrap/css/dataTables.bootstrap.css' %}"/>
{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row clearfix">
<h4 style="margin-bottom: 10px; margin-top: 10px; padding-left: 15px">NUEVA INCIDENCIA</h4>
</div>
<div class="body">
<form action= "{% url 'incid:newincid' %}" method="post" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Submit</button>
{% endbuttons %}
</form>
{{ form.errors }}
</div>
</div>
{% endblock %}
extending a standard base with no references to either prioridad, tipo or estado.
Nevertheless, when rendered, tipo and estado show the initial values but prioridad doesn't. I have rewritten view, form and template from scratch twice as I couldn't find a typo but it still happens. I would appreciate any clues or hints on what to do.
Note: This is a revisitation of another problem I posted that I do not know how to delete or edit.