mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Updated API URLs
This commit is contained in:
parent
9a9a039fc9
commit
e06121ebda
12
InvenTree/InvenTree/api_urls.py
Normal file
12
InvenTree/InvenTree/api_urls.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.conf.urls import url, include
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.site_header = "InvenTree Admin"
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^stock/', include('stock.urls')),
|
||||
url(r'^part/', include('part.api_urls')),
|
||||
url(r'^supplier/', include('supplier.urls')),
|
||||
url(r'^track/', include('track.urls')),
|
||||
url(r'^project/', include('project.api_urls'))
|
||||
]
|
@ -79,6 +79,13 @@ class InvenTreeTree(models.Model):
|
||||
|
||||
return unique
|
||||
|
||||
@property
|
||||
def children(self):
|
||||
contents = ContentType.objects.get_for_model(type(self))
|
||||
children = contents.get_all_objects_for_this_type(parent=self.id)
|
||||
|
||||
return children
|
||||
|
||||
def getAcceptableParents(self):
|
||||
""" Returns a list of acceptable parent items within this model
|
||||
Acceptable parents are ones which are not underneath this item.
|
||||
|
@ -1,25 +1,10 @@
|
||||
"""InvenTree URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.10/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.site_header = "InvenTree Admin"
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include('InvenTree.api_urls')),
|
||||
url(r'^stock/', include('stock.urls')),
|
||||
url(r'^part/', include('part.urls')),
|
||||
url(r'^supplier/', include('supplier.urls')),
|
||||
|
17
InvenTree/part/api_urls.py
Normal file
17
InvenTree/part/api_urls.py
Normal file
@ -0,0 +1,17 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
# Display part detail
|
||||
url(r'^(?P<pk>[0-9]+)/$', views.PartDetail.as_view()),
|
||||
|
||||
# Display a single part category
|
||||
url(r'^category/(?P<pk>[0-9]+)/$', views.PartCategoryDetail.as_view()),
|
||||
|
||||
# Display a list of top-level categories
|
||||
url(r'^category/$', views.PartCategoryList.as_view()),
|
||||
|
||||
# Display list of all parts
|
||||
url(r'^$', views.PartList.as_view())
|
||||
]
|
@ -15,6 +15,12 @@ class PartCategory(InvenTreeTree):
|
||||
verbose_name = "Part Category"
|
||||
verbose_name_plural = "Part Categories"
|
||||
|
||||
@property
|
||||
def parts(self):
|
||||
parts_list = self.part_set.all()
|
||||
print(parts_list)
|
||||
return parts_list
|
||||
|
||||
|
||||
class Part(models.Model):
|
||||
""" Represents a """
|
||||
|
@ -4,14 +4,21 @@ from .models import Part, PartCategory, PartParameter
|
||||
|
||||
|
||||
class ParameterSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a PartParameter
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = PartParameter
|
||||
fields = ('name',
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'value',
|
||||
'units')
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
class PartDetailSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for complete detail information of a part.
|
||||
Used when displaying all details of a single component.
|
||||
"""
|
||||
|
||||
params = ParameterSerializer(source='parameters', many=True)
|
||||
|
||||
@ -26,11 +33,44 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
'params')
|
||||
|
||||
|
||||
class PartCategorySerializer(serializers.ModelSerializer):
|
||||
class PartBriefSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for displaying overview of a part.
|
||||
Used e.g. for displaying list of parts in a category.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'IPN',
|
||||
'description',
|
||||
'category',
|
||||
'stock')
|
||||
|
||||
|
||||
class PartCategoryBriefSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'description')
|
||||
|
||||
|
||||
class PartCategoryDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
# List of parts in this category
|
||||
parts = PartBriefSerializer(many=True)
|
||||
|
||||
# List of child categories under this one
|
||||
children = PartCategoryBriefSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'description',
|
||||
'parent',
|
||||
'path')
|
||||
'path',
|
||||
'children',
|
||||
'parts')
|
||||
|
@ -3,15 +3,9 @@ from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
# Display part detail
|
||||
url(r'^(?P<pk>[0-9]+)/$', views.PartDetail.as_view()),
|
||||
# part landing page
|
||||
url(r'^$', views.part_index),
|
||||
|
||||
# Display a single part category
|
||||
url(r'^category/(?P<pk>[0-9]+)/$', views.PartCategoryDetail.as_view()),
|
||||
|
||||
# Display a list of top-level categories
|
||||
url(r'^category/$', views.PartCategoryList.as_view()),
|
||||
|
||||
# Display list of parts
|
||||
url(r'^$', views.PartList.as_view())
|
||||
# part category landing page
|
||||
url(r'^category/$', views.category_index)
|
||||
]
|
||||
|
@ -4,32 +4,38 @@ from django.http import HttpResponse, Http404
|
||||
from rest_framework import generics
|
||||
|
||||
from .models import PartCategory, Part
|
||||
from .serializers import PartSerializer, PartCategorySerializer
|
||||
from .serializers import PartBriefSerializer, PartDetailSerializer
|
||||
from .serializers import PartCategoryBriefSerializer, PartCategoryDetailSerializer
|
||||
|
||||
|
||||
def index(request):
|
||||
def part_index(request):
|
||||
return HttpResponse("Hello world. This is the parts page")
|
||||
|
||||
def category_index(request):
|
||||
return HttpResponse("This is the category page")
|
||||
|
||||
class PartDetail(generics.RetrieveAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
serializer_class = PartDetailSerializer
|
||||
|
||||
|
||||
class PartList(generics.ListAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
serializer_class = PartBriefSerializer
|
||||
|
||||
|
||||
class PartCategoryDetail(generics.RetrieveAPIView):
|
||||
|
||||
""" Return information on a single PartCategory
|
||||
"""
|
||||
queryset = PartCategory.objects.all()
|
||||
serializer_class = PartCategorySerializer
|
||||
serializer_class = PartCategoryDetailSerializer
|
||||
|
||||
|
||||
class PartCategoryList(generics.ListAPIView):
|
||||
|
||||
queryset = PartCategory.objects.all()
|
||||
serializer_class = PartCategorySerializer
|
||||
""" Return a list of all top-level part categories.
|
||||
Categories are considered "top-level" if they do not have a parent
|
||||
"""
|
||||
queryset = PartCategory.objects.filter(parent=None)
|
||||
serializer_class = PartCategoryBriefSerializer
|
||||
|
6
InvenTree/project/api_urls.py
Normal file
6
InvenTree/project/api_urls.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
]
|
Loading…
Reference in New Issue
Block a user