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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e2672373-5cc1-495d-8d46-5e99bdf58fbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to