mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Added projects API
This commit is contained in:
parent
3704ad34dc
commit
0ca8a75166
@ -17,6 +17,10 @@ class ProjectCategory(InvenTreeTree):
|
|||||||
verbose_name = "Project Category"
|
verbose_name = "Project Category"
|
||||||
verbose_name_plural = "Project Categories"
|
verbose_name_plural = "Project Categories"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def projects(self):
|
||||||
|
return self.project_set.all()
|
||||||
|
|
||||||
|
|
||||||
class Project(models.Model):
|
class Project(models.Model):
|
||||||
""" A Project takes multiple Part objects.
|
""" A Project takes multiple Part objects.
|
||||||
@ -57,7 +61,7 @@ class ProjectPart(models.Model):
|
|||||||
quantity = models.PositiveIntegerField(default=1)
|
quantity = models.PositiveIntegerField(default=1)
|
||||||
overage = models.FloatField(default=0)
|
overage = models.FloatField(default=0)
|
||||||
overage_type = models.PositiveIntegerField(
|
overage_type = models.PositiveIntegerField(
|
||||||
default=1,
|
default=OVERAGE_ABSOLUTE,
|
||||||
choices=OVARAGE_CODES.items())
|
choices=OVARAGE_CODES.items())
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
66
InvenTree/project/serializers.py
Normal file
66
InvenTree/project/serializers.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from .models import ProjectCategory, Project, ProjectPart
|
||||||
|
|
||||||
|
from part.serializers import PartBriefSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPartSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectPart
|
||||||
|
fields = ('pk',
|
||||||
|
'part',
|
||||||
|
'project',
|
||||||
|
'quantity',
|
||||||
|
'overage',
|
||||||
|
'overage_type')
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectBriefSerializer(serializers.ModelSerializer):
|
||||||
|
""" Serializer for displaying brief overview of a project
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = ('pk',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'category')
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectDetailSerializer(serializers.ModelSerializer):
|
||||||
|
""" Serializer for detailed project information
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Project
|
||||||
|
fields = ('pk',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'category')
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectCategoryBriefSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectCategory
|
||||||
|
fields = ('pk','name','description')
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectCategoryDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
projects = ProjectBriefSerializer(many=True)
|
||||||
|
|
||||||
|
children = ProjectCategoryBriefSerializer(many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ProjectCategory
|
||||||
|
fields = ('pk',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'parent',
|
||||||
|
'path',
|
||||||
|
'children',
|
||||||
|
'projects')
|
@ -3,5 +3,18 @@ from django.conf.urls import url
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.index, name='index')
|
# Single project detail
|
||||||
|
url(r'^(?P<pk>[0-9]+)/$', views.ProjectDetail.as_view()),
|
||||||
|
|
||||||
|
# Parts associated with a project
|
||||||
|
url(r'^(?P<pk>[0-9]+)/parts$', views.ProjectPartsList.as_view()),
|
||||||
|
|
||||||
|
# List of all projects
|
||||||
|
url(r'^$', views.ProjectList.as_view()),
|
||||||
|
|
||||||
|
# List of top-level project categories
|
||||||
|
url(r'^category/$', views.ProjectCategoryList.as_view()),
|
||||||
|
|
||||||
|
# Detail of a single project category
|
||||||
|
url(r'^category/(?P<pk>[0-9]+)/$', views.ProjectCategoryDetail.as_view())
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,39 @@
|
|||||||
from django.http import HttpResponse
|
from rest_framework import generics
|
||||||
|
|
||||||
|
from .models import ProjectCategory, Project, ProjectPart
|
||||||
|
from .serializers import ProjectBriefSerializer, ProjectDetailSerializer
|
||||||
|
from .serializers import ProjectCategoryBriefSerializer, ProjectCategoryDetailSerializer
|
||||||
|
from .serializers import ProjectPartSerializer
|
||||||
|
|
||||||
|
class ProjectDetail(generics.RetrieveAPIView):
|
||||||
|
|
||||||
|
queryset = Project.objects.all()
|
||||||
|
serializer_class = ProjectDetailSerializer
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class ProjectList(generics.ListAPIView):
|
||||||
return HttpResponse("This is the Projects page")
|
|
||||||
|
queryset = Project.objects.all()
|
||||||
|
serializer_class = ProjectBriefSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectCategoryDetail(generics.RetrieveAPIView):
|
||||||
|
|
||||||
|
queryset = ProjectCategory.objects.all()
|
||||||
|
serializer_class = ProjectCategoryDetailSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectCategoryList(generics.ListAPIView):
|
||||||
|
|
||||||
|
queryset = ProjectCategory.objects.filter(parent=None)
|
||||||
|
serializer_class = ProjectCategoryDetailSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPartsList(generics.ListAPIView):
|
||||||
|
|
||||||
|
serializer_class = ProjectPartSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
project_id = self.kwargs['pk']
|
||||||
|
return ProjectPart.objects.filter(project=project_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user