Programmatically create fields

Not sure if this is possible - or a good idea - but…

I have a model with a number of Boolean fields that are all handled the same. Say I have a database of articles I have written, and I want to note which I have published on Facebook, which I have put on my blog, etc. I want to have a list of field names, and use that to generate fields.

    flags = ['facebook', 'blog']
    for s in flags:
        <what here?> = models.BooleanField(default=False)

I appreciate if the flags list changes, it has to be migrated; I am assuming that will be rare, but occasionally desired.

Is this possible?

Yes.

I think you’d need to do this in a custom subclass of the ModelBase Metaclass though, and not in the Model class itself.

Probably a really bad idea though. Without a lot of testing, I have no idea how this would integrate with things like static code checkers, or the migration system. (Superficially, I think it would work ok with the admin and ModelForms.)