How To Implement Dynamic Columns in Django models based on POST request

251 Views Asked by At

I have created a Django RestFramework with few models like Offers, Dailysubs and Requisitions to which I need add columns dynamically for a POST request.

There should be 1-10 blank columns for a model and a Master table which has fields to configure the new column like name and other properties.

I also need to implement an approach to add these dynamic columns into serializers.

class Requisition(models.Model):
    skill = models.CharField(max_length=255)
    superClass = models.CharField(max_length=255)
    jobFamily = models.CharField(max_length=255)
    yearOfExp = models.CharField(max_length=255)
    grade = models.CharField(max_length=100)
    ...
    ...
class Offer(models.Model):
    businessGroup = models.CharField(max_length=100)
    status = models.CharField(max_length=20)
    sNo = models.IntegerField()
    recruiter = models.CharField(max_length=100)
    manager = models.CharField(max_length=100)
    dateOfOffer = models.DateField()
    dateOfJoining = models.DateField()
    ...
    ...
class MasterTable(models.Model):
    columnName = models.CharField(max_length=100)
    tableName = models.CharField(max_length=100)
    columnFieldType = models.CharField(max_length=100)

I read another post related to this at Django Models (dynamic?) but I don't know if I should create another model to hold these blank columns or if I should add blank columns to each model.

0

There are 0 best solutions below