I want to have some permissions on few contents, which are NOT models
, but are 'name' in the following table:
mysql> select * from my_contents;
+----+---------------------+
| id | name |
+----+---------------------+
| 1 | content1 |
| 2 | content2 |
I understand that Django's Permission model requires a ContentType instance. So, I also inserted these 2 entries in django_content_type table
with arbitrary app_label
and model
.
Something like:
| 20 | content1 | some_label | content1 |
| 21 | content2 | some_label | content2 |
Now, I was thinking that on running syncdb
permissions for these 2 new contents will be created automatically in auth_permission
, but instead, I get:
The following content types are stale and need to be deleted:
some_label | content1
some_label | content2
How do I update the permissions for these 2 contents (without model) ?
What you are attempting to do sounds like per object permissions. For each object within a model you want to set permissions on it. Django does not support this but django-guardian does. If you look at the link it provides a simple example on how to achieve this outcome.
If you really want to have a permission that does not have a matching model then have a look at this snippet. Have not tested it personaly