Stock API now hyperlinkd

This commit is contained in:
Oliver Walters 2017-04-14 23:44:24 +10:00
parent 9e3fa00fdd
commit 7c5261bc4a
4 changed files with 14 additions and 10 deletions

View File

@ -35,6 +35,7 @@ class InvenTreeTree(models.Model):
class Meta:
abstract = True
unique_together = ('name', 'parent')
name = models.CharField(max_length=100)
description = models.CharField(max_length=250, blank=True)

View File

@ -3,13 +3,13 @@ from rest_framework import serializers
from .models import StockItem, StockLocation
class StockItemSerializer(serializers.ModelSerializer):
class StockItemSerializer(serializers.HyperlinkedModelSerializer):
""" Serializer for a StockItem
"""
class Meta:
model = StockItem
fields = ('pk',
fields = ('url',
'part',
'location',
'quantity',
@ -20,13 +20,13 @@ class StockItemSerializer(serializers.ModelSerializer):
'expected_arrival')
class LocationSerializer(serializers.ModelSerializer):
class LocationSerializer(serializers.HyperlinkedModelSerializer):
""" Detailed information about a stock location
"""
class Meta:
model = StockLocation
fields = ('pk',
fields = ('url',
'name',
'description',
'parent',

View File

@ -3,11 +3,11 @@ from django.conf.urls import url, include
from . import views
locpatterns = [
url(r'^(?P<pk>[0-9]+)/?$', views.LocationDetail.as_view(), name='location-detail'),
url(r'^(?P<pk>[0-9]+)/?$', views.LocationDetail.as_view(), name='stocklocation-detail'),
url(r'^\?.*/?$', views.LocationList.as_view(), name='location-list'),
url(r'^\?.*/?$', views.LocationList.as_view()),
url(r'^$', views.LocationList.as_view(), name='location-list')
url(r'^$', views.LocationList.as_view())
]
urlpatterns = [
@ -15,9 +15,9 @@ urlpatterns = [
url(r'^location/', include(locpatterns)),
# Detail for a single stock item
url(r'^(?P<pk>[0-9]+)/?$', views.StockDetail.as_view(), name='stock-detail'),
url(r'^(?P<pk>[0-9]+)/?$', views.StockDetail.as_view(), name='stockitem-detail'),
# List all stock items, with optional filters
url(r'^\?.*/?$', views.StockList.as_view(), name='stock-list'),
url(r'^$', views.StockList.as_view(), name='stock-list'),
url(r'^\?.*/?$', views.StockList.as_view()),
url(r'^$', views.StockList.as_view()),
]

View File

@ -31,6 +31,9 @@ class SupplierPart(models.Model):
- A Part may be available from multiple suppliers
"""
class Meta:
unique_together = ('part', 'supplier', 'SKU')
part = models.ForeignKey(Part, null=True, blank=True, on_delete=models.CASCADE)
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)
SKU = models.CharField(max_length=100)