I want to create something similar to Microsoft Access Design View
in django model using these model:
class Type(models.Model):
TYPE_OF_DATA = (
('Number', 'Number'),
('character', 'character'),
('boolean', 'boolean'),
('date', 'date'),
('image', 'image'),
)
data_type = models.CharField(max_length=1000, choices= TYPE_OF_DATA)
def __str__(self):
return self.data_type
class Column(models.Model):
name = models.CharField(max_length=100)
selec_type = models.ForeignKey(Type, on_delete= models.CASCADE)
class Table(models.Model):
number = models.IntegerField()
character = models.CharField(max_length=30)
check_box = models.BooleanField()
date = models.DateField()
image = models.ImageField(upload_to='image-table')
I successfully created 30 Column in the form:
From .forms import ColumnForm
From django.forms import modelformset_factory
def design(request):
ColumnFormSet = modelformset_factory(Column, fields = ('name', 'selec_type'), extra=30)
formset = ColumnFormSet
if request.method == 'POST':
formset = ColumnFormSet(request.POST)
if formset.is_valid():
formset.save()
return redirect('Home')
else:
formset = ColumnFormSet()
return render (request, 'design.html', {'formset':formset})
Using this view, a user can create a name
of a field and assign it to the data type
that a user want the field to be stored.
My problem here is the Table
model, where user can store all the information based on the Column
table he created or design. How can I archive that using django?