2016-04-07 19 views

cevap

0

(ı önlemek istiyorum yönetici sayfasına giderek hariç) diğer bir yolu yoktur,

students = Group(name='Students') 
students.save() 

somemodel_ct = ContentType.objects.get(app_label='course', model='course') 

can_view = Permission(name='Can View', codename='can_view_something', 
         content_type=somemodel_ct) 
can_view.save() 

can_modify = Permission(name='Can Modify', codename='can_modify_something', 
         content_type=somemodel_ct) 

can_create = Permission(name='Can Create', codename='can_create_something', 
         content_type=somemodel_ct) 

can_delete = Permission(name='Can Delete', codename='can_delete_something', 
         content_type=somemodel_ct) 


can_delete.save() 

Ama bu bana çirkin görünüyor: Bu ne yaptım :

class Entity(models.Model): 
    class Meta: 
     # Remove default permissions, remove this line to keep them 
     default_permissions = dict() 

     # Custom permissions 
     permissions = (
      ("add_leadmarket", "Add new lead market"), 
      ("edit_leadmarket", "Edit lead market"), 
      ("delete_leadmarket", "Delete lead market"), 
      ("list_leadmarket", "See list of lead markets"), 
      ("view_leadmarket", "View lead market profile"), 
     ) 

    user = models.OneToOneField(User) 
    parent = models.ManyToManyField(User, related_name='parents', blank=True) 
    # ...