Django - Mostrar los campos en filas con inline formset usando UpdateWithInlinesView

 
Vista:

Mostrar los campos en filas con inline formset usando UpdateWithInlinesView

Publicado por Susana (1 intervención) el 15/10/2019 21:35:04
Buenas tardes estoy usando UpdateWithInlinesView ,django-extras-views para inline formset
y necesito mostrar los campos en linea queria ver si alguien me puede ayudar

models.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Notas_Alumno(models.Model):
    Estados = (('Activo', 'Activo'), ('Inactivo', 'Inactivo'),)
    years=models.ForeignKey(YYYY, on_delete=models.PROTECT,verbose_name='Año')
    codgrado=models.ForeignKey(GradoSeccion,on_delete=models.PROTECT,verbose_name='Grado')
    codmateria=models.ForeignKey(Materias_Grado, on_delete=models.PROTECT,null=True, blank=True,verbose_name='Materia')
    estado = models.CharField(max_length=10, choices=Estados, default='Activo',verbose_name='Estado')
    created_fecha = models.DateTimeField(auto_now_add=True, null=True, blank=True)
    updated_fecha = models.DateTimeField(auto_now=True, null=True, blank=True)
 
    def __str__(self):
         return '%s-%s-%s' %(self.years,self.codgrado,self.codmateria)
 
class DetalleNotasP1(models.Model):
    Estados = (('Completo', 'Completo'), ('Incompleto', 'Incompleto'),)
    id_notasalumno=models.ForeignKey(Notas_Alumno,on_delete=models.PROTECT, verbose_name='Codigo')
    cod_alumno = models.ForeignKey(Alumnos, on_delete=models.PROTECT, verbose_name='Alumno')
    P101=models.DecimalField(max_digits=4, decimal_places=2, default=0,verbose_name='Nota 1')
    P102=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 2')
    P103=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 3')
    P104=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 4')
    P105=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 5')
    P106=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 6')
    P107=models.DecimalField(max_digits=4,decimal_places=2,default=0,verbose_name='Nota 7')
    P108=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 8')
    P109=models.DecimalField(max_digits=4,decimal_places=2,default=0, verbose_name='Nota 9')
    P110=models.DecimalField(max_digits=4,decimal_places=2,default=0,verbose_name='Nota 10')
    PromP1=models.DecimalField(max_digits=4,decimal_places=2,default=0,verbose_name='Nota Final')
    estado = models.CharField(max_length=10, choices=Estados, default='Incompleto', verbose_name='Estado')
    created_fecha = models.DateTimeField(auto_now_add=True, null=True, blank=True)
    updated_fecha = models.DateTimeField(auto_now=True, null=True, blank=True)



views.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class DetalleInline(InlineFormSetFactory):
    model = DetalleNotasP1
    fields = '__all__'
    form_class = DetalleNotasP1Form
 
 
class UpdateDetalleView(UpdateWithInlinesView):
    model = Notas_Alumno
    inlines = [DetalleInline]
    fields = '__all__'
    template_name = 'notas/editdetallenotasalumnos.html'
    success_url = "/notas/listarnotasalumno/"
 
 
forms.py
class NotasAlumnoForm(ModelForm):
    class Meta:
        model = Notas_Alumno
        fields= '__all__'
 
class DetalleNotasP1Form(ModelForm):
    class Meta:
        model = DetalleNotasP1
        fields = '__all__'
 
 
DetalleNotasP1FormSet = inlineformset_factory(Notas_Alumno, DetalleNotasP1, fields= '__all__',
                                              formset=DetalleNotasP1Form, extra=2,can_delete=True)
 
 
notas/editdetallenotasalumnos.html
{% extends 'bases/base.html' %}
{% load static %}
{% block contenido %}
    <div class="container-fluid">
 
                <div class="row page-titles">
                    <div class="col-md-5 col-8 align-self-center">
                        <h3 class="text-themecolor m-b-0 m-t-0">Listado Historial</h3>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:void(0)">Inicio</a></li>
                            <li class="breadcrumb-item active">Alumnos</li>
                        </ol>
                    </div>
 
                </div>
 
<div class="row">
    <div class="col s12">
 
          <div class="card">
               <div class="card-body">
                   <h5 class="card-title"></h5>
                        <form method="POST">{% csrf_token %}
                            {{ form.as_p }}
                             <div class="table-responsive">
 
                                <table class="table striped m-b-20" id="editable-datatable">
 
                                                <thead>
                                                    <tr>
                                                        <th>Id</th>
                                                        <th>NotasAlumno</th>
                                                        <th>Alumno</th>
                                                        <th>Nota 1</th>
                                                        <th>Nota 2</th>
                                                        <th>Nota 3</th>
                                                        <th>Nota 4</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                 {% for formset in inlines %}
                                                         <tr>
                                                             <td> {{formset}} </td>
                                                          </tr>
                                                        {% endfor %}
                                                </tbody>
                                </table>
                                <input type="submit" value="Save"/> <a href="{% url 'notas:notasalumnos_list' %}">back to the list</a>
                             </div>
                         </form>
                    </div>
                </div>
         </div>
    </div>
</div>
 
{% endblock %}


Pero me lo despliega en una sola columna los campos y se requiere en fila tipo tabla .que puedo hacer se los agradeceria mucho me diferan como ya intente varias formas pero nada les dejo la parte mas sencilla
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder