<repo_name>kekatoz/zxcv<file_sep>/zxcv12/testt/urls.py
from django.urls import path
from .views import get, fine

urlpatterns = [
    path('', get),
    path('fine/', fine)
]
<file_sep>/zxcv12/testt/forms.py
from django import forms


class Testform(forms.Form):
    testfield= forms.CharField(label='testfield', max_length=255)

<file_sep>/zxcv12/testt/migrations/0002_auto_20210203_1727.py
# Generated by Django 3.0 on 2021-02-03 14:27

import django.contrib.postgres.fields.jsonb
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('testt', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='InputModel',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('field', models.CharField(max_length=255)),
                ('data', django.contrib.postgres.fields.jsonb.JSONField()),
            ],
        ),
        migrations.DeleteModel(
            name='TestModel',
        ),
    ]
<file_sep>/zxcv12/testt/views.py
from django.shortcuts import render, redirect
from .forms import Testform
from .models import Testmodel
import json


def get(request):
    if request.method == 'POST':
        form = Testform(request.POST)
        if form.is_valid():
            name_input = form.cleaned_data['testfield']
            data = json.dumps(name_input, ensure_ascii=False)
            Testmodel.objects.create(data=data, field='testfield')
            for count in range(1, len(request.POST) - 1):
                query = 'field' + str(count)
                input_value = request.POST[query]
                if input_value:
                    data = json.dumps(input_value, ensure_ascii=False)
                    field = json.dumps(query)
                    Testmodel.objects.create(data=data, field=field)
                count += 1
        return redirect('/fine/')
    else:
        form = Testform()
    return render(request, 'base.html', {'form': form})


def fine(request):
    # Take data from the db
    query = Testmodel.objects.all().values('id', 'data', 'field')
    json_list = list(query)
    return render(request, 'fine.html', {'json_list': json_list})
<file_sep>/zxcv12/testt/models.py
from django.db import models
from django.contrib.postgres.fields import JSONField


# Create your models here.

class Testmodel(models.Model):
    field = models.TextField(max_length=255)
    data = JSONField()

    def __str__(self):
        return self.field, self.data
<file_sep>/zxcv12/testt/migrations/0005_auto_20210205_1031.py
# Generated by Django 3.0 on 2021-02-05 10:31

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('testt', '0004_auto_20210203_1901'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='InputModel',
            new_name='Testmodel',
        ),
    ]
