How to add dynamic fields at runtime in django

I need to add dynamic fields at runtime in my django application, but I don't know how to correctly add new fields at runtime.

I want to add code that will generate a dynamic field, and will also update the database. I am using postgresql database. please help if anyone can.

My "model.py" looks like this:

class Student(models.Model):

    name=models.CharField(max_length=100)
    school=models.CharField(max_length=100)
    created_at=models.DateField(auto_now_add=True)  
    is_active=models.BooleanField(default=False)


    def __str__(self):
        return self.name
+4
source share
1 answer

Django is not intended for dynamic models since there are no relational databases. Changing the model at run time will cause a ton of problems.

You have to imitate it, ...

  • , . JSON
  • , , ; PK, FK, .

, , .

+2

Source: https://habr.com/ru/post/1609762/


All Articles