Compare commits

..

No commits in common. "74e0be71b9eba456397dfba2d58ce70fc14995ce" and "6c6ef9e5fc5f75fad0954817679e449d2ab126a9" have entirely different histories.

4 changed files with 14 additions and 71 deletions

View File

@ -24,43 +24,22 @@ class PackageSerializer(serializers.HyperlinkedModelSerializer):
model = parts_models.Package model = parts_models.Package
fields = '__all__' fields = '__all__'
class ComponentParameterSerializer(serializers.HyperlinkedModelSerializer): class StorageSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField() full_path = serializers.ReadOnlyField(source='get_full_path')
ro_parameter_type = serializers.ReadOnlyField(source='parameter_type.parameter_name')
class Meta:
model = parts_models.ComponentParameter
fields = '__all__'
class ComponentDistributorNumSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
class Meta: class Meta:
model = parts_models.DistributorNum model = parts_models.Storage
fields = '__all__' fields = ['url', 'id', 'name', 'verbose_name', 'parent_storage', 'responsible', 'template', 'full_path']
class ComponentSerializer(serializers.HyperlinkedModelSerializer): class ComponentSerializer(serializers.HyperlinkedModelSerializer):
package_data = PackageSerializerNoLink(source='package', read_only=True) package_data = PackageSerializerNoLink(source='package', read_only=True)
ro_manufacturer_name = serializers.ReadOnlyField(source='manufacturer.name') ro_manufacturer_name = serializers.ReadOnlyField(source='manufacturer.name')
ro_image = serializers.ReadOnlyField(source='get_resolved_image') ro_image = serializers.ReadOnlyField(source='get_resolved_image')
ro_component_type = serializers.ReadOnlyField(source='component_type.class_name')
ro_parameters = ComponentParameterSerializer(many=True, source='componentparameter_set', read_only=True)
ro_distributor_numbers = ComponentDistributorNumSerializer(many=True, source='distributornum_set', read_only=True)
class Meta: class Meta:
model = parts_models.Component model = parts_models.Component
fields = ['url', fields = ['url', 'id', 'name', 'package_data', 'package', 'pref_distri', 'image', 'manufacturer', 'ro_manufacturer_name', 'ro_image']
'id',
'name',
'package_data',
'package',
'pref_distri',
'image',
'manufacturer',
'component_type',
'ro_manufacturer_name',
'ro_image',
'ro_component_type',
'ro_parameters',
'ro_distributor_numbers']
class StockSerializer(serializers.HyperlinkedModelSerializer): class StockSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField() id = serializers.ReadOnlyField()
@ -72,22 +51,6 @@ class StockSerializer(serializers.HyperlinkedModelSerializer):
model = parts_models.Stock model = parts_models.Stock
fields = '__all__' fields = '__all__'
class StockSerializerExpandComponent(StockSerializer):
ro_component = ComponentSerializer(read_only=True, source='component')
class StorageSerializer(serializers.HyperlinkedModelSerializer):
full_path = serializers.ReadOnlyField(source='get_full_path')
class Meta:
model = parts_models.Storage
fields = ['url', 'id', 'name', 'verbose_name', 'parent_storage', 'responsible', 'template', 'full_path']
class StorageSerializerStocksExpanded(StorageSerializer):
ro_stocks = StockSerializerExpandComponent(many=True, read_only=True, source='stock_set')
class Meta(StorageSerializer.Meta):
fields = StorageSerializer.Meta.fields + ['ro_stocks']
class DistributorSerializer(serializers.HyperlinkedModelSerializer): class DistributorSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField() id = serializers.ReadOnlyField()
class Meta: class Meta:

View File

@ -1,6 +1,7 @@
from django.urls import include, path, re_path from django.urls import include, path
from rest_framework import routers from rest_framework import routers
from .views import * from .views import *
from django.conf.urls import url
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'users', UserViewSet) router.register(r'users', UserViewSet)
@ -8,8 +9,6 @@ router.register(r'groups', GroupViewSet)
router.register(r'parts/storages', PartsStorageViewSet) router.register(r'parts/storages', PartsStorageViewSet)
router.register(r'parts/storage_templates', PartsStorageTemplatesViewSet, basename='storage-template') router.register(r'parts/storage_templates', PartsStorageTemplatesViewSet, basename='storage-template')
router.register(r'parts/components', PartsComponentViewSet) router.register(r'parts/components', PartsComponentViewSet)
router.register(r'parts/component-parameters', PartsComponentParameterViewSet)
router.register(r'parts/component-distributor-numbers', PartsComponentDistributorNumViewSet)
router.register(r'parts/stocks', PartsStockViewSet) router.register(r'parts/stocks', PartsStockViewSet)
router.register(r'parts/packages', PartsPackageViewSet) router.register(r'parts/packages', PartsPackageViewSet)
router.register(r'parts/distributors', PartsDistributorviewSet) router.register(r'parts/distributors', PartsDistributorviewSet)
@ -19,6 +18,6 @@ router.register(r'parts/component-param-types', PartsComponentParameterTypeViewS
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), path('', include(router.urls)),
re_path(r'^token-auth/', ObtainExpiringAuthToken.as_view()), url(r'^token-auth/', ObtainExpiringAuthToken.as_view()),
re_path(r'^token-logout/', TokenLogout.as_view()), url(r'^token-logout/', TokenLogout.as_view()),
] ]

View File

@ -42,16 +42,12 @@ class GroupViewSet(viewsets.ReadOnlyModelViewSet):
class PartsStorageViewSet(viewsets.ModelViewSet): class PartsStorageViewSet(viewsets.ModelViewSet):
queryset = parts_models.Storage.objects.all() queryset = parts_models.Storage.objects.all()
serializer_class = StorageSerializer
permission_classes = [permissions.DjangoModelPermissions] permission_classes = [permissions.DjangoModelPermissions]
filter_backends = [django_filters.rest_framework.DjangoFilterBackend] filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
search_fields = ['id', 'name', 'parent_storage'] search_fields = ['id', 'name', 'parent_storage']
filterset_fields = ['id', 'name', 'parent_storage'] filterset_fields = ['id', 'name', 'parent_storage']
def get_serializer_class(self):
if self.request.GET.get('expand_stocks'):
return StorageSerializerStocksExpanded
return StorageSerializer
class PartsStorageTemplatesViewSet(viewsets.ReadOnlyModelViewSet): class PartsStorageTemplatesViewSet(viewsets.ReadOnlyModelViewSet):
queryset = parts_models.Storage.objects.filter(is_template=True) queryset = parts_models.Storage.objects.filter(is_template=True)
serializer_class = StorageSerializer serializer_class = StorageSerializer
@ -68,22 +64,6 @@ class PartsComponentViewSet(viewsets.ModelViewSet):
search_fields = ['id', 'name', 'package__name', 'manufacturer__name'] search_fields = ['id', 'name', 'package__name', 'manufacturer__name']
filterset_fields = ['id', 'name'] filterset_fields = ['id', 'name']
class PartsComponentParameterViewSet(viewsets.ModelViewSet):
queryset = parts_models.ComponentParameter.objects.all()
serializer_class = ComponentParameterSerializer
permission_classes = [permissions.DjangoModelPermissions]
filter_backends = [filters.SearchFilter, django_filters.rest_framework.DjangoFilterBackend]
search_fields = ['id', 'parameter_type__parameter_name']
filterset_fields = ['id']
class PartsComponentDistributorNumViewSet(viewsets.ModelViewSet):
queryset = parts_models.DistributorNum.objects.all()
serializer_class = ComponentDistributorNumSerializer
permission_classes = [permissions.DjangoModelPermissions]
filter_backends = [filters.SearchFilter, django_filters.rest_framework.DjangoFilterBackend]
search_fields = ['id', 'distributor', 'distributor_part_number']
filterset_fields = ['id']
class PartsComponentTypeViewSet(viewsets.ModelViewSet): class PartsComponentTypeViewSet(viewsets.ModelViewSet):
queryset = parts_models.ComponentType.objects.all() queryset = parts_models.ComponentType.objects.all()
serializer_class = ComponentTypeSerializer serializer_class = ComponentTypeSerializer

View File

@ -14,13 +14,14 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include, re_path from django.urls import path, include
from django.conf.urls import url
from django.conf.urls.static import static from django.conf.urls.static import static
from django.conf import settings from django.conf import settings
from parts import views as parts_views from parts import views as parts_views
urlpatterns = [ urlpatterns = [
re_path(r'^admin/login/', parts_views.login_view), url(r'^admin/login/', parts_views.login_view),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/v1/', include('api.urls'), name='api-root'), path('api/v1/', include('api.urls'), name='api-root'),
path('', include('parts.urls')), path('', include('parts.urls')),