mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
Start adding tastypie subresources
This commit is contained in:
@@ -2,12 +2,20 @@
|
|||||||
|
|
||||||
from tastypie.resources import ModelResource
|
from tastypie.resources import ModelResource
|
||||||
from tastypie.authentication import BasicAuthentication
|
from tastypie.authentication import BasicAuthentication
|
||||||
|
from tastypie import fields #, utils
|
||||||
|
|
||||||
from lib.api.auth import AcomAuthorization
|
from lib.api.auth import AcomAuthorization
|
||||||
|
from lib.api.resources.projects import Projects
|
||||||
|
from lib.api.resources.users import Users
|
||||||
|
|
||||||
import lib.main.models as models
|
import lib.main.models as models
|
||||||
|
|
||||||
class Organizations(ModelResource):
|
class Organizations(ModelResource):
|
||||||
|
|
||||||
|
users = fields.ToManyField(Users, 'users')
|
||||||
|
admins = fields.ToManyField(Users, 'admins')
|
||||||
|
projects = fields.ToManyField(Projects, 'projects')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
queryset = models.Organization.objects.all()
|
queryset = models.Organization.objects.all()
|
||||||
resource_name = 'organizations'
|
resource_name = 'organizations'
|
||||||
|
|||||||
16
lib/api/resources/projects.py
Normal file
16
lib/api/resources/projects.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# myapp/api.py
|
||||||
|
|
||||||
|
from tastypie.resources import ModelResource
|
||||||
|
from tastypie.authentication import BasicAuthentication
|
||||||
|
from lib.api.auth import AcomAuthorization
|
||||||
|
import lib.main.models as models
|
||||||
|
|
||||||
|
class Projects(ModelResource):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
queryset = models.Project.objects.all()
|
||||||
|
resource_name = 'projects'
|
||||||
|
authentication = BasicAuthentication()
|
||||||
|
authorization = AcomAuthorization()
|
||||||
|
|
||||||
|
|
||||||
16
lib/api/resources/users.py
Normal file
16
lib/api/resources/users.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# myapp/api.py
|
||||||
|
|
||||||
|
from tastypie.resources import ModelResource
|
||||||
|
from tastypie.authentication import BasicAuthentication
|
||||||
|
from lib.api.auth import AcomAuthorization
|
||||||
|
import lib.main.models as models
|
||||||
|
|
||||||
|
class Users(ModelResource):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
queryset = models.User.objects.all()
|
||||||
|
resource_name = 'users'
|
||||||
|
authentication = BasicAuthentication()
|
||||||
|
authorization = AcomAuthorization()
|
||||||
|
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class CommonModel(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
name = models.CharField(max_length=512)
|
name = models.CharField(max_length=512, unique=True)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
creation_date = models.DateField(auto_now_add=True)
|
creation_date = models.DateField(auto_now_add=True)
|
||||||
tags = models.ManyToManyField('Tag', related_name='%(class)s_tags', blank=True)
|
tags = models.ManyToManyField('Tag', related_name='%(class)s_tags', blank=True)
|
||||||
@@ -163,9 +163,6 @@ class Project(CommonModel):
|
|||||||
A project represents a playbook git repo that can access a set of inventories
|
A project represents a playbook git repo that can access a set of inventories
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class Meta:
|
|
||||||
app_label = 'main'
|
|
||||||
|
|
||||||
inventories = models.ManyToManyField('Inventory', blank=True, related_name='projects')
|
inventories = models.ManyToManyField('Inventory', blank=True, related_name='projects')
|
||||||
local_repository = models.CharField(max_length=1024)
|
local_repository = models.CharField(max_length=1024)
|
||||||
scm_type = models.CharField(max_length=64)
|
scm_type = models.CharField(max_length=64)
|
||||||
|
|||||||
Reference in New Issue
Block a user