mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Project API improvements
- Added DetailView for ProjectPart - Improved URL structure
This commit is contained in:
parent
04524d38ab
commit
b13f135d8e
@ -9,9 +9,17 @@ from . import views
|
||||
projectdetailpatterns = [
|
||||
# Single project detail
|
||||
url(r'^$', views.ProjectDetail.as_view()),
|
||||
]
|
||||
|
||||
projectpartpatterns = [
|
||||
# Detail of a single project part
|
||||
url(r'^(?P<pk>[0-9]+)/$', views.ProjectPartDetail.as_view()),
|
||||
|
||||
# Parts associated with a project
|
||||
url(r'^parts/$', views.ProjectPartsList.as_view()),
|
||||
url(r'^\?[^/]*/$', views.ProjectPartsList.as_view()),
|
||||
|
||||
# All project parts
|
||||
url(r'^$', views.ProjectPartsList.as_view()),
|
||||
]
|
||||
|
||||
projectcategorypatterns = [
|
||||
@ -23,7 +31,6 @@ projectcategorypatterns = [
|
||||
|
||||
# Create a new category
|
||||
url(r'^new/$', views.NewProjectCategory.as_view())
|
||||
|
||||
]
|
||||
|
||||
urlpatterns = [
|
||||
@ -34,6 +41,9 @@ urlpatterns = [
|
||||
# List of all projects
|
||||
url(r'^$', views.ProjectList.as_view()),
|
||||
|
||||
# Project parts
|
||||
url(r'^parts/', include(projectpartpatterns)),
|
||||
|
||||
# Project categories
|
||||
url(r'^category/', include(projectcategorypatterns)),
|
||||
]
|
||||
|
@ -58,10 +58,23 @@ class ProjectPartsList(generics.ListCreateAPIView):
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
def get_queryset(self):
|
||||
project_id = self.kwargs['pk']
|
||||
return ProjectPart.objects.filter(project=project_id)
|
||||
project_id = self.request.query_params.get('project', None)
|
||||
|
||||
if project_id:
|
||||
return ProjectPart.objects.filter(project=project_id)
|
||||
else:
|
||||
return ProjectPart.objects.all()
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
# Ensure project link is set correctly
|
||||
request.data['project'] = self.kwargs['pk']
|
||||
request.data['project'] = self.request.query_params.get('project', None)
|
||||
return super(ProjectPartsList, self).create(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ProjectPartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""" Detail for a single project part
|
||||
"""
|
||||
|
||||
queryset = ProjectPart.objects.all()
|
||||
serializer_class = ProjectPartSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
Loading…
Reference in New Issue
Block a user