I know you can have permissions on individual models that control which users have access to them, but I need something for my apps.
Ex. If a user logs in, does he have access to the store_app? The forum_app? etc.
I have a solution that looks something like this:
models.py:
class MyUser(AbstractUser):
for app_short_name, app_long_name in settings.APP_CHOICES:
add_field = "allow_{} = ".format(app_short_name)
add_field += "models.BooleanField(verbose_name='Allow Access to {}', default=False, null=False)".format(app_long_name)
exec(add_field)
settings.py:
APP_CHOICES = [
('store_app', 'Store App'),
('forum_app', 'Forum App'),
]
It works, but I'm not sure if it's bad practice to have dynamically generated fields in models.py like this, or if there's a better/simpler way to do this.