mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Start adding tastypie subresources
This commit is contained in:
parent
1d6c035df1
commit
690af95a50
@ -2,16 +2,24 @@
|
||||
|
||||
from tastypie.resources import ModelResource
|
||||
from tastypie.authentication import BasicAuthentication
|
||||
from tastypie import fields #, utils
|
||||
|
||||
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
|
||||
|
||||
class Organizations(ModelResource):
|
||||
|
||||
users = fields.ToManyField(Users, 'users')
|
||||
admins = fields.ToManyField(Users, 'admins')
|
||||
projects = fields.ToManyField(Projects, 'projects')
|
||||
|
||||
class Meta:
|
||||
queryset = models.Organization.objects.all()
|
||||
resource_name = 'organizations'
|
||||
authentication = BasicAuthentication()
|
||||
authorization = AcomAuthorization()
|
||||
|
||||
|
||||
|
||||
|
||||
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:
|
||||
abstract = True
|
||||
|
||||
name = models.CharField(max_length=512)
|
||||
name = models.CharField(max_length=512, unique=True)
|
||||
description = models.TextField()
|
||||
creation_date = models.DateField(auto_now_add=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
|
||||
'''
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
|
||||
inventories = models.ManyToManyField('Inventory', blank=True, related_name='projects')
|
||||
local_repository = models.CharField(max_length=1024)
|
||||
scm_type = models.CharField(max_length=64)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user