mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 10:10:01 -03:30
Add support for related resources, and all present related resources on the organization object.
Implementation of sub services still on deck.
This commit is contained in:
@@ -1,15 +1,38 @@
|
||||
from django.contrib.auth.models import User as DjangoUser
|
||||
from lib.main.models import User, Organization, Project
|
||||
from rest_framework import serializers, pagination
|
||||
|
||||
# FIXME: add all fields here
|
||||
# FIXME: make proper fields read only
|
||||
# FIXME: add URLs for sub resources like /organizations/2/projects/
|
||||
from django.core.urlresolvers import reverse
|
||||
import lib.urls
|
||||
|
||||
class OrganizationSerializer(serializers.ModelSerializer):
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
# add the URL and related resources
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
related = serializers.SerializerMethodField('get_related')
|
||||
|
||||
# make certain fields read only
|
||||
creation_date = serializers.DateTimeField(read_only=True)
|
||||
active = serializers.BooleanField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Organization
|
||||
fields = ('url', 'id', 'name', 'description')
|
||||
|
||||
# whitelist the fields we want to show
|
||||
fields = ('url', 'id', 'name', 'description', 'creation_date', 'related')
|
||||
|
||||
def get_related(self, obj):
|
||||
''' related resource URLs '''
|
||||
|
||||
return dict(
|
||||
audit_trail = reverse(lib.urls.views_OrganizationsAuditTrailList, args=(obj.pk,)),
|
||||
projects = reverse(lib.urls.views_OrganizationsProjectsList, args=(obj.pk,)),
|
||||
users = reverse(lib.urls.views_OrganizationsUsersList, args=(obj.pk,)),
|
||||
admins = reverse(lib.urls.views_OrganizationsAdminsList, args=(obj.pk,)),
|
||||
tags = reverse(lib.urls.views_OrganizationsTagsList, args=(obj.pk,))
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user