mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Tracking API is hyperlinked
This commit is contained in:
parent
7c5261bc4a
commit
a1db0c90e4
@ -45,7 +45,6 @@ class SupplierPartSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SupplierPart
|
model = SupplierPart
|
||||||
#extra_kwargs = {'url': {'view_name': 'supplier-part-detail'}}
|
|
||||||
fields = ['url',
|
fields = ['url',
|
||||||
'part',
|
'part',
|
||||||
'supplier',
|
'supplier',
|
||||||
|
@ -37,6 +37,10 @@ class UniquePart(models.Model):
|
|||||||
and tracking all events in the life of a part
|
and tracking all events in the life of a part
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
# Cannot have multiple parts with same serial number
|
||||||
|
unique_together = ('part', 'serial')
|
||||||
|
|
||||||
objects = UniquePartManager()
|
objects = UniquePartManager()
|
||||||
|
|
||||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
||||||
@ -50,7 +54,7 @@ class UniquePart(models.Model):
|
|||||||
editable=False)
|
editable=False)
|
||||||
serial = models.IntegerField()
|
serial = models.IntegerField()
|
||||||
|
|
||||||
createdBy = models.ForeignKey(User)
|
# createdBy = models.ForeignKey(User)
|
||||||
|
|
||||||
customer = models.ForeignKey(Customer, blank=True, null=True)
|
customer = models.ForeignKey(Customer, blank=True, null=True)
|
||||||
|
|
||||||
@ -76,17 +80,6 @@ class UniquePart(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.part.name
|
return self.part.name
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
|
|
||||||
# Disallow saving a serial number that already exists
|
|
||||||
matches = UniquePart.objects.filter(serial=self.serial, part=self.part)
|
|
||||||
matches = matches.filter(~models.Q(id=self.id))
|
|
||||||
|
|
||||||
if len(matches) > 0:
|
|
||||||
raise ValidationError(_("Matching serial number already exists"))
|
|
||||||
|
|
||||||
super(UniquePart, self).save(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class PartTrackingInfo(models.Model):
|
class PartTrackingInfo(models.Model):
|
||||||
""" Single data-point in the life of a UniquePart
|
""" Single data-point in the life of a UniquePart
|
||||||
|
@ -3,24 +3,24 @@ from rest_framework import serializers
|
|||||||
from .models import UniquePart, PartTrackingInfo
|
from .models import UniquePart, PartTrackingInfo
|
||||||
|
|
||||||
|
|
||||||
class UniquePartSerializer(serializers.ModelSerializer):
|
class UniquePartSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
tracking_info = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
tracking_info = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UniquePart
|
model = UniquePart
|
||||||
fields = ['pk',
|
fields = ['url',
|
||||||
'part',
|
'part',
|
||||||
'revision',
|
'revision',
|
||||||
'creation_date',
|
'creation_date',
|
||||||
'serial',
|
'serial',
|
||||||
'createdBy',
|
# 'createdBy',
|
||||||
'customer',
|
'customer',
|
||||||
'status',
|
'status',
|
||||||
'tracking_info']
|
'tracking_info']
|
||||||
|
|
||||||
|
|
||||||
class PartTrackingInfoSerializer(serializers.ModelSerializer):
|
class PartTrackingInfoSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PartTrackingInfo
|
model = PartTrackingInfo
|
||||||
|
@ -3,19 +3,19 @@ from django.conf.urls import url, include
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
infopatterns = [
|
infopatterns = [
|
||||||
url(r'^(?P<pk>[0-9]+)/?$', views.PartTrackingDetail.as_view(), name='tracking-detail'),
|
url(r'^(?P<pk>[0-9]+)/?$', views.PartTrackingDetail.as_view(), name='parttrackinginfo-detail'),
|
||||||
|
|
||||||
url(r'^\?.*/?$', views.PartTrackingList.as_view(), name='tracking-list'),
|
url(r'^\?.*/?$', views.PartTrackingList.as_view()),
|
||||||
url(r'^$', views.PartTrackingList.as_view(), name='tracking-list')
|
url(r'^$', views.PartTrackingList.as_view())
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'info/', include(infopatterns)),
|
url(r'info/', include(infopatterns)),
|
||||||
|
|
||||||
# Detail for a single unique part
|
# Detail for a single unique part
|
||||||
url(r'^(?P<pk>[0-9]+)/?$', views.UniquePartDetail.as_view(), name='unique-detail'),
|
url(r'^(?P<pk>[0-9]+)/?$', views.UniquePartDetail.as_view(), name='uniquepart-detail'),
|
||||||
|
|
||||||
# List all unique parts, with optional filters
|
# List all unique parts, with optional filters
|
||||||
url(r'^\?.*/?$', views.UniquePartList.as_view(), name='unique-list'),
|
url(r'^\?.*/?$', views.UniquePartList.as_view()),
|
||||||
url(r'^$', views.UniquePartList.as_view(), name='unique-list'),
|
url(r'^$', views.UniquePartList.as_view()),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user