“Django Group oleh” Kode Jawaban

Django Group oleh

# If you mean to do aggregation you can use the aggregation features of the ORM:
from django.db.models import Count
Members.objects.values('designation').annotate(dcount=Count('designation'))

# This results in a query similar to:
SELECT designation, COUNT(designation) AS dcount
FROM members GROUP BY designation

#and the output would be of the form
[{'designation': 'Salesman', 'dcount': 2}, 
 {'designation': 'Manager', 'dcount': 2}]
Repulsive Raven

Buat grup Django

from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from api.models import Project
new_group, created = Group.objects.get_or_create(name='new_group')
# Code to add permission to group ???
ct = ContentType.objects.get_for_model(Project)

# Now what - Say I want to add 'Can add project' permission to new_group?
permission = Permission.objects.create(codename='can_add_project',
                                   name='Can add project',
                                   content_type=ct)
new_group.permissions.add(permission)
JThayil

Jawaban yang mirip dengan “Django Group oleh”

Pertanyaan yang mirip dengan “Django Group oleh”

Lebih banyak jawaban terkait untuk “Django Group oleh” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya