Answers for "how to add new column in django"

0

how to add new column in django

#add new column to django db

from django.db.models import CharField
from django.db.models.signals import class_prepared

def add_field(sender, **kwargs):
    """
    class_prepared signal handler that checks for the model named
    MyModel as the sender, and adds a CharField
    to it.
    """
    if sender.__name__ == "MyModel":
        field = CharField("New field", max_length=100)
        field.contribute_to_class(sender, "new_field")

class_prepared.connect(add_field)
Posted by: Guest on July-27-2020

Code answers related to "how to add new column in django"

Python Answers by Framework

Browse Popular Code Answers by Language