Django - Clean permission table -


during development apps , models permissions removed or renamed. what's way clean leftovers permissions table without breaking something?

for example: have app articles model article permissions.

class article(models.model):     title = ...     text = ...      class meta:         permissions = (             ('can_edit_title', 'can edit title of article'),             ('can_edit_text', 'can edit text of article'),         ) 

i add permission command (with installed django_extension):

./manage update_permissions 

but later realise, better name can_update_title. change model:

class article(models.model):     ...      class meta:         permissions = (             ('can_update_title', 'can update title of article'),             ('can_update_text', 'can update text of article'),         ) 

when update permissions there both permissions in django administration , confusing users - administrators.

short answer: register permission admin site. add admin.py file:

from django.contrib.auth.models import permission admin.site.register(permission) 

then control there.

long answer: permission objects, else in django. saved database, , linked linked users , groups through manytomany relationship. when changed name of permission in meta class of article model, django had no way of knowing still ment same object before, instead created new one.

what should've done was, after changing name of permission in model change name of correlating permission object in database.

the easiest way register permission object admin site, you'd have control there. you'd still need change in both places (models.py , db) name change, admin site makes easier.

keep in mind permission object created ('update') has new pk, meaning if delete older permission object ('edit') have consequences on had relation with. if have data don't want lose suggest writing script merge 2 permission objects avoid errors


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -