10👍
You have 2 solutions here, AFAIK :
- manually insert in the
auth_permission
table ; - Add in a command this snippet.
Adding a command is pretty straightforward. Just create a module sync_perms.py
(with the snippet code) in a management.commands
package in one of your apps (here the official documentation).
Then run :
python manage.py sync_perms
Et voilà !
1👍
Just posted the solution to
Remove (or hide) default Permissions from Django.
The idea is not to prevent them from being created by syncdb, but to hide them from the admin interface.
- [Django]-ElasticSearch term suggest on analyzed field returns no suggestions
- [Django]-ModuleNotFoundError : no module named : crispy_forms
1👍
first you must find the content type id for your application the content type
can be found with this query
select * from django_content_type;
then you execute the query to add to database the custom permission you want for example
insert into auth_permission(name,content_type_id,codename) values
('Can add name',12,'can_add_name');
in the above query , name is a string which the user see in permissions list , the number is the application id found from the first query and codename is the code that you will use in templates for example in template you can use
{{perms.application.can_add_name}}
- [Django]-Django_crontab not working on production docker
- [Django]-Can I have 2 Django sites using 2 different version of Python on 1 domain?
- [Django]-How can I get an access to url paramaters in django rest framework permission class?
0👍
You need to specify default_permissions
on Meta to be empty tuple. (default value is ('add', 'change', 'delete')
). Docs.
class MyModel(models.Model):
# properties definition...
class Meta:
permissions = (
("admin", "Can create/edit/delete projects"),
("user", "Can view projects"),
)
default_permissions = ()
I also like to have special MyAppProperties
model with Meta.managed=False
to hold my app-wide permissions.
class MyAppPermissions(models.Model):
# properties definition...
class Meta:
managed = False
permissions = (
("admin", "Can create/edit/delete projects"),
("user", "Can view projects"),
)
default_permissions = ()
this way it won’t create a database table, but permissions for it. Docs.
- [Django]-Initial form data from model – Django
- [Django]-Django: related_name attribute (DatabaseError)
- [Django]-Django-compressor + less compress the files but link to original files