Skip to content

Instantly share code, notes, and snippets.

@JamCh01
Created December 21, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamCh01/252d7463ec048f254b44b19c60f8953e to your computer and use it in GitHub Desktop.
Save JamCh01/252d7463ec048f254b44b19c60f8953e to your computer and use it in GitHub Desktop.
models.py
from django.db import models
from django.db.models.base import ModelBase
def models_generator(db_table):
class CustomMetaClass(ModelBase):
def __new__(cls, name, bases, attrs):
model = super(CustomMetaClass, cls).__new__(
cls, name, bases, attrs)
model._meta.db_table = db_table
print(db_table)
return model
class CustomModel(models.Model, metaclass=CustomMetaClass):
# Field
pass
return CustomModel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment