Using django-tables2 I try to have 2 dimensions table. I tried to make this 
using accessors with the docs here 
<https://django-tables2.readthedocs.io/en/latest/pages/custom-data.html> 
But it doesn't work at all. 

I don't seen any example and I don't know if it's possible. Has anyone has 
an idea? 

Here my code : 



#views.py
def visualiserTableResult(request):
   choix= request.POST['type_donnees']
   sample = Sample.objects.all()
   antibiotique = Antibiotique.objects.all()
   data = []
   for s in sample:
     for a in antibiotique:
        echantillon = 
Echantillon.objects.filter(antibiotique_id=a.antibio_id).filter(sample_id=s.sample_id).values(
            'echantillon_id')
        if choix == "C":
            res = 
Resultats.objects.filter(echantillon_id=echantillon).values_list("res_C")
        if choix == "S":
            res = 
Resultats.objects.filter(echantillon_id=echantillon).values_list('res_S', 
flat=True)
        if choix == "d":
            res = 
Resultats.objects.filter(echantillon_id=echantillon).values_list('res_d', 
flat=True)

        data.append({s: {a:  res}})
   table = GeneralTable(data)
   RequestConfig(request).configure(table)
   return render(request, 'resistance/visualiserTableResult.html', {'table': 
table})

#tables.py
class GeneralTable(tables.Table):
   sample = tables.Column(accessor=('s'))
   antibiotique = tables.Column(attrs={'th': {'antibiotique': 'a'}})

   class Meta:
     attrs = {'class': 'paleblue'}

#models.py
class Echantillon (models.Model):
   echantillon_id = models.IntegerField(primary_key=True)
   antibiotique = models.ForeignKey('Antibiotique', on_delete=models.CASCADE)
   sample = models.ForeignKey(Sample, on_delete=models.CASCADE)
   resistance = models.ManyToManyField(
    'Type_resistance',
    through='Resultats'
)

class Resultats (models.Model):
   resultats_id = models.IntegerField(primary_key=True)
   echantillon = models.ForeignKey('Echantillon', on_delete=models.CASCADE)
   resistance = models.ForeignKey('Type_resistance', on_delete=models.CASCADE)
   res_C = models.DecimalField(max_digits=5, decimal_places=2,null=True)
   res_S = models.CharField(max_length=10, null=True)
   res_d = models.DecimalField(max_digits=5, decimal_places=2, null=True)
   comment = models.TextField(null=True)


I want to have a table with values of "antibiotique" in headers and result 
for each sample.I hope that someone have an idea

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/609f3837-7389-4237-89a3-1fa45eba796f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to