I looked up the answer 
(http://stackoverflow.com/questions/6062655/remove-or-hide-default-permissions-from-django),
 
it worked, but suddenly it stopped working, i am not sure, what i did or if 
I reinstaled something. I have this solution:

from django.contrib import admin
from django.contrib.auth.models import Permission
from django.contrib.auth.models import User, Group
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.contrib.auth.forms import UserChangeForm

#
# In the models listed below standard permissions "add_model", 
"change_model"
# and "delete_model" will be created by syncdb, but hidden from admin 
interface.
# This is convenient in case you use your own set of permissions so the list
# in the admin interface wont be confusing.
# Feel free to add your models here. The first element is the app name 
(this is
# the directory your app is in) and the second element is the name of your 
model
# from models.py module of your app (Note: both names must be lowercased).
#
MODELS_TO_HIDE_STD_PERMISSIONS = (
    ("auth", "permission"),
    ("auth", "group"),
    ("auth", "user"),
    ("contenttypes", "contenttype"),
    ("sessions", "session"),
    ("sites", "site"),
    ("admin", "logentry"),
    ("mainpage","novinkymodel"),
    ("mainpage", "komentarknovinkymodel"),
    ("mainpage", "clovek"),
    ("mainpage", "ucitel"),
    ("mainpage", "trida"),
    ("mainpage", "predmety"),
    ("mainpage", "administrator"),
    ("mainpage", "student"),
    ("mainpage", "rodic"),
    ("kalendar", "udalost"),
    ("fotogalerie", "slozka"),
    ("fotogalerie", "fotka"),
    ("south", "migrationhistory")
    )

def _get_corrected_permissions():
    perms = Permission.objects.all()
    for app_name, model_name in MODELS_TO_HIDE_STD_PERMISSIONS:
        perms = perms.exclude(content_type__app_label=app_name, 
codename='add_%s' % model_name)
        perms = perms.exclude(content_type__app_label=app_name, 
codename='change_%s' % model_name)
        perms = perms.exclude(content_type__app_label=app_name, 
codename='delete_%s' % model_name)
    return perms

class MyGroupAdminForm(forms.ModelForm):

    class Meta:
        model = Group

    permissions = forms.ModelMultipleChoiceField(
        _get_corrected_permissions(),
        widget=admin.widgets.FilteredSelectMultiple(('permissions'), False),
        help_text = 'Hold down "Control", or "Command" on a Mac, to select 
more than one.'
    )

class MyGroupAdmin(GroupAdmin):

    form = MyGroupAdminForm

class MyUserChangeForm(UserChangeForm):

    user_permissions = forms.ModelMultipleChoiceField(
        _get_corrected_permissions(),
        widget=admin.widgets.FilteredSelectMultiple(('user_permissions'), 
False),
        help_text = 'Hold down "Control", or "Command" on a Mac, to select 
more than one.'
    )

class MyUserAdmin(UserAdmin):

    form = MyUserChangeForm

admin.site.unregister(Group)
admin.site.register(Group, MyGroupAdmin)
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)



I am using Django 1.6.4 and Python 3.4. This code is in my app and file 
admin.py

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f5c18da-d3ef-45d9-9e30-fb4f8837fb47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to