Commit ea0913fe authored by Ashish's avatar Ashish
Browse files

Changes per standards

parent de89d8e3
......@@ -56,4 +56,4 @@ dist: clean
python setup.py bdist_wheel
ls -l dist
build: clean test lint
\ No newline at end of file
build: clean test lint
......@@ -51,6 +51,16 @@ class AlchemyModelSerializer(serializers.Serializer):
mapper = class_mapper(self.cls.__class__)
try:
# URI field for get pk field
pk_field = primary_key(self.cls.__class__)
except KeyNotFoundException:
return ret
r = self.context['request']
ret['href'] = AlchemyUriField(source=pk_field,
path=r.build_absolute_uri(r.path))
# Get all the Column fields
for col_prop in mapper.iterate_properties:
if isinstance(col_prop, ColumnProperty):
......@@ -66,7 +76,6 @@ class AlchemyModelSerializer(serializers.Serializer):
for rel_prop in mapper.iterate_properties:
if isinstance(rel_prop, RelationshipProperty):
field_nm = str(rel_prop).split('.')[1]
r = self.context['request']
# many becomes same as uselist so that
# RelatedField can iterate over the queryset
ret[field_nm] = AlchemyRelatedField(source=field_nm,
......@@ -88,8 +97,8 @@ class AlchemyListSerializer(AlchemyModelSerializer):
return ret
request = self.context['request']
ret[pk_field] = AlchemyUriField(source=pk_field,
path=request.build_absolute_uri(
request.path))
ret["href"] = AlchemyUriField(source=pk_field,
path=request.build_absolute_uri(
request.path))
return ret
......@@ -81,16 +81,16 @@ class AlchemyModelViewSet(MultipleObjectMixin, ManagerMixin, viewsets.ViewSet):
queryset = mgr.list(other_pks=self.get_other_pks(request),
filters=request.QUERY_PARAMS)
serializer = self.serializer_factory(True, queryset,
mgr.model_class(),
{'request': request})
if self.paginate_by:
try:
queryset = self.get_page(queryset)
except InvalidPage:
return Response({}, status.HTTP_400_BAD_REQUEST)
serializer = self.serializer_factory(True, queryset,
mgr.model_class(),
{'request': request})
return Response(serializer.data)
def retrieve(self, request, **kwargs):
......
......@@ -55,7 +55,8 @@ session = Session()
for i in range(0, 50):
car = Car(car_id=i, make='Toyota', model='Prius', year='2014')
part = Part(car_id=i, part_id=i + 1, part_description='Engine', part_num=random.randint(0, 1000))
part = Part(car_id=i, part_id=i + 1, part_description='Engine',
part_num=random.randint(0, 1000))
session.add(car)
session.add(part)
......
# Django settings for app project.
# ignore=E501
DEBUG = True
TEMPLATE_DEBUG = DEBUG
......@@ -11,8 +12,8 @@ MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'sqlite.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment