Z
Z
zhanka_sun2018-07-31 09:07:40
Django
zhanka_sun, 2018-07-31 09:07:40

How to populate a table from different database tables?

Hello! I need to populate a table with data from different postgresql tables. To fill the first column I wrote the code like this:

{%for i in word_kaz%} 
                    <tr>
                        <td> {{i.words}} </td> 
                    </tr>
{%endfor%}

then everything outputs fine, but I need to fill 4 columns, and for this I write like this:
{%for i in word_kaz%} 
                    <tr>
                        <td> {{i.words}} </td>     
                        <td> {{i.emotions}} </td>    
                        <td> {{i.tr_rus}} </td>     
                        <td> {{i.tr_eng}} </td>     
                    </tr>
 {%endfor%}

But then the second column only starts after the first one ends (that is, how the stairs are rendered). All tables have the same length, so I wrote it in one cycle. I tried to write a cycle for each separately, but then the table is filled not in length but in width.
views:
def dic_tonal(request, pk):

    word_kaz = wordkaz.objects.all()
    emo = emotion.objects.all()
    rus_dic = rus.objects.all()
    eng_dic = eng.objects.all()

    return render(request, 'app/dic_tonal.html',{
        'word_kaz': word_kaz,
        'emo': emo,
        'rus_dic': rus_dic,
        'eng_dic': eng_dic,
        })

Models:
class wordkaz(models.Model):
    words = models.TextField()
class emotion(models.Model):
    emotions = models.TextField()
class rus(models.Model):
    tr_rus = models.TextField()
class eng(models.Model):
    tr_eng = models.TextField()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question