I need to mimic a *spreadsheet* with Django for a simple school app like 
'*task/student 
> score*', so I have this models:

   - Actividad (tasks)
   - Alumno (students) > M2M to 'Actividad' through 'Calificacion'
   - Calificacion (scores)

I don't know how to proceed, if I need a formset or whatever, and I can't 
find any help in Django mailing list for this. I know how to show, through 
'Calificacion' intermediate table, all this data but only for already 
registered rows.

I end using *get_context_data()* to show a list from 'Actividad' (tasks) on 
the left and all the students related to it in the table header, and a form 
with input values on each cell.

But this is not what I want because the *user must see all* the 'Actividad' 
(tasks) and 'Alumno' (students) and their 'Calificacion' (scores) *whenever 
it exists or not* in the intermediate table.

P.S. Really, I try my best to explain myself but it isn't easy ;) Then ask 
me whatever you need to know and thanks for your interest!


# Desing
+-----------+----------+----------+| Actividad | alumno_1 | alumno_2 
|+===========+==========+==========+|  activ_1  |     5*   |    4     
|+-----------+----------+----------+|  activ_2  |     8    |  EMPTY   
|+-----------+----------+----------+*numbers  > Calificacion.nota 
(scores)*alumno_1 > Alumno.nombre (students)*activ_1  > Actividad.nombre (tasks)

# models.py
class Alumno(models.Model):
    curso = models.ForeignKey(Curso)
    calificaciones = models.ManyToManyField(
        Actividad, through='Calificacion', blank=True, null=True)

    nombre = models.CharField(max_length=150)

class Calificacion(models.Model):
    alumno = models.ForeignKey(Alumno, blank=True, null=True)
    actividad = models.ForeignKey(Actividad, blank=True, null=True)

    nota = models.IntegerField(blank=True, null=True)

# views.py
class CalificacionMixin(object):
    model = Calificacion
    form_class = CalificacionForm
    template_name = 'registros/calificaciones.html'

    def get_context_data(self, **kwargs):
        context = super(CalificacionMixin, self).get_context_data(**kwargs)

        self.tarea_id = self.kwargs['tareaid']
        tarea = Tarea.objects.filter(id=self.tarea_id)

        actividades = Actividad.objects.filter(tarea=tarea)
        context['actividades'] = actividades

        curso = Curso.objects.filter(tarea=tarea)
        alumnos = Alumno.objects.filter(curso=curso)
        context['alumnos'] = alumnos

        context['calificaciones'] = Calificacion.objects.all()

        return context

class CalificacionCreate(CalificacionMixin, CreateView):
    pass

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to