“groupe de django par” Réponses codées

groupe de django par

# 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

Créer un groupe 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

Réponses similaires à “groupe de django par”

Questions similaires à “groupe de django par”

Plus de réponses similaires à “groupe de django par” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code