Load data from the database with AJAX in a table in my UpdateView template

1

I want to load the saved data that are in the database of question options, I have in my model

class Pregunta(models.Model):
    contenido = models.TextField(max_length=1000, blank=False, help_text="Entre la pregunta que quiere que se muestre:",
                                 verbose_name='Pregunta')
    status = models.CharField(max_length=1, choices=STATUS_PREGUNTA)
    tipo_pregunta = models.CharField(max_length=2, choices=TIPO_PREGUNTA)

class OpcionRespuesta(models.Model):
    """Clase para los posibles tipos de respuesta"""
    contenido = models.TextField(max_length=1000, blank=True, null=True,
                             help_text="Entre la opcion de respuesta que sera mostrada", verbose_name="Contenido")
    correcta = models.BooleanField(blank=False, default=False, help_text="Es esta la respuesta correcta?",
                               verbose_name="Correcta")
    pregunta = models.ForeignKey(Pregunta, on_delete=models.CASCADE, verbose_name="Pregunta")

This is what I have in my update template:

 <table id= "tabla_su_sm"  class="table table-condensed" style="margin-bottom: 0">
   <tbody id="su_options_list">
    <tr id="template_SU" class="not-removable" style="display: none;">
     <td width="70%">
      <label class="item-text" style="padding-left: 10px; padding-top: 7px">
       Este ejemplo de opción puede ser eliminado
      </label>
     </td>
     <td width="15%" align="center">
      <a class="btn check-su" data-value="False">
       <span class="glyphicon glyphicon-unchecked"></span>
      </a>
     </td>
     <td width="15%" align="center">
      <a class="btn remove-item-su-sm">
       <span class="glyphicon glyphicon-remove-sign"></span>
      </a>
     </td>
    </tr>
    ...
</table>

I want to fill that table with the data of the selected question type. Running the server looks like this.

I hope you can help me, if you need more information tell me.

    
asked by Aime Martínez 24.07.2017 в 23:52
source

0 answers