This repository was archived by the owner on May 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Ozon uk homework 3 #79
Open
ozon-uk
wants to merge
8
commits into
upy:main
Choose a base branch
from
ozon-uk:ozon-uk-homework-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
486bc11
For Baskets app: serializers added,filters added, viewsets added to v…
b615f92
For customers app: serializers added,filters added, viewsets added to…
ad894a0
For orders app: serializers added,filters added, viewsets added to views
88de4ca
For payments app: serializers added,filters added, viewsets added to …
44f3854
For products app: serializers and filters for stock and price models …
2cb9e31
Router registrations made for each endpoint, needed configurations fo…
89a0b3d
README.md file updated
a6cd742
Explanatory comments added
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from django_filters import rest_framework as filters | ||
|
|
||
| from baskets.models import Basket, BasketItem | ||
|
|
||
| #Basket Filter | ||
| class BasketFilter(filters.FilterSet): | ||
| class Meta: | ||
| model = Basket | ||
| fields = ('customer', 'status') | ||
|
|
||
| #Basket Item Filter | ||
| class BasketItemFilter(filters.FilterSet): | ||
| class Meta: | ||
| model = BasketItem | ||
| fields = ("basket", "product", "quantity", "price") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from rest_framework import serializers | ||
|
|
||
| from baskets.models import Basket, BasketItem | ||
| from customers.serializers import CustomerSerializer | ||
| from products.serializers import ProductSerializer | ||
|
|
||
|
|
||
| # Basket Serializer | ||
| class BasketSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Basket | ||
| fields = ('id', 'customer', 'status') | ||
|
|
||
|
|
||
| # Basket Detailed Serializer - nested serializer | ||
| class BasketDetailedSerializer(BasketSerializer): | ||
| customers = CustomerSerializer() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. customers yanlış olmuş customer olmalı |
||
|
|
||
|
|
||
| # Basket Item Serializer | ||
| class BasketItemSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = BasketItem | ||
| fields = ('id', 'basket', 'product', 'quantity', 'price') | ||
|
|
||
|
|
||
| # Basket Item Detailed Serializer - nested serializer | ||
| class BasketItemDetailedSerializer(BasketItemSerializer): | ||
| baskets = BasketSerializer() | ||
| products = ProductSerializer() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,29 @@ | ||
| from django.shortcuts import render | ||
| from rest_framework import viewsets | ||
|
|
||
| # Create your views here. | ||
| from baskets.filters import BasketFilter, BasketItemFilter | ||
| from baskets.models import Basket, BasketItem | ||
| from baskets.serializers import BasketSerializer, BasketItemSerializer, BasketDetailedSerializer, \ | ||
| BasketItemDetailedSerializer | ||
| from core.mixins import DetailedViewSetMixin | ||
|
|
||
|
|
||
| # Basket ViewSet | ||
| class BasketViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = Basket.objects.all() | ||
| serializer_class = BasketSerializer | ||
| filterset_class = BasketFilter | ||
| serializer_action_classes = { | ||
| "detailed_list": BasketDetailedSerializer, | ||
| "detailed": BasketDetailedSerializer, | ||
| } | ||
|
|
||
|
|
||
| # Basket Item ViewSet | ||
| class BasketItemViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = BasketItem.objects.all() | ||
| serializer_class = BasketItemSerializer | ||
| filterset_class = BasketItemFilter | ||
| serializer_action_classes = { | ||
| "detailed_list": BasketItemDetailedSerializer, | ||
| "detailed": BasketItemDetailedSerializer, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from django_filters import rest_framework as filters | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from customers.models import Customer, City, Country, Address | ||
|
|
||
|
|
||
| # Customer Filter | ||
| class CustomerFilter(filters.FilterSet): | ||
| first_name = filters.CharFilter(label=_("First Name"), | ||
| lookup_expr="icontains") | ||
| last_name = filters.CharFilter(label=_("Last Name"), | ||
| lookup_expr="icontains") | ||
| email = filters.CharFilter(label=_("Email"), lookup_expr="icontains") | ||
|
|
||
| class Meta: | ||
| model = Customer | ||
| fields = ("first_name", "last_name", "email", "is_staff", "is_active") | ||
|
|
||
|
|
||
| # City Filter | ||
| class CityFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("City"), lookup_expr="icontains") | ||
|
|
||
| class Meta: | ||
| model = City | ||
| fields = ("name", "country") | ||
|
|
||
|
|
||
| # Country Filter | ||
| class CountryFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("Country"), lookup_expr="icontains") | ||
|
|
||
| class Meta: | ||
| model = Country | ||
| fields = ("name",) | ||
|
|
||
|
|
||
| # Address Filter | ||
| class AddressFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("Address"), lookup_expr="icontains") | ||
|
|
||
| class Meta: | ||
| model = Address | ||
| fields = ( | ||
| "name", "full_name", "phone", "district", "zipcode", "customer", | ||
| "city",) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from rest_framework import serializers | ||
|
|
||
| from customers.models import City, Country, Customer, Address | ||
|
|
||
|
|
||
| # City Serializer | ||
| class CitySerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = City | ||
| fields = ('id', 'name', 'country') | ||
|
|
||
|
|
||
| # Country Serializer | ||
| class CountrySerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Country | ||
| fields = ('id', 'name') | ||
|
|
||
|
|
||
| # Customer Serializer | ||
| class CustomerSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Customer | ||
| fields = ('id', 'first_name', 'last_name', 'email', 'is_staff', 'is_active', 'date_joined') | ||
|
|
||
|
|
||
| # Address Serializer | ||
| class AddressSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Address | ||
| fields = ( | ||
| 'id', 'customer', 'name', 'full_name', 'line_1', 'line_2', 'phone', 'district', 'zipcode', 'city', | ||
| 'is_default') | ||
|
|
||
|
|
||
| # City Detailed Serializer - nested serializer | ||
| class CityDetailedSerializer(CitySerializer): | ||
| countries = CountrySerializer() | ||
|
|
||
|
|
||
| # Address Detailed Serializer - nested serializer | ||
| class AddressDetailedSerializer(AddressSerializer): | ||
| customers = CustomerSerializer | ||
| cities = CitySerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,41 @@ | ||
| from django.shortcuts import render | ||
| from rest_framework import viewsets | ||
|
|
||
| # Create your views here. | ||
| from core.mixins import DetailedViewSetMixin | ||
| from customers.filters import AddressFilter, CityFilter, CustomerFilter, CountryFilter | ||
| from customers.models import City, Country, Customer, Address | ||
| from customers.serializers import CitySerializer, CountrySerializer, CustomerSerializer, AddressSerializer, \ | ||
| CityDetailedSerializer, AddressDetailedSerializer | ||
|
|
||
|
|
||
| class CityViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = City.objects.all() | ||
| serializer_class = CitySerializer | ||
| filterset_class = CityFilter | ||
| serializer_action_classes = { | ||
| "detailed_list": CityDetailedSerializer, | ||
| "detailed": CityDetailedSerializer, | ||
| } | ||
|
|
||
|
|
||
| class CountryViewSet(viewsets.ModelViewSet): | ||
| queryset = Country.objects.all() | ||
| serializer_class = CountrySerializer | ||
| filterset_class = CountryFilter | ||
|
|
||
|
|
||
| # Customer ViewSet | ||
| class CustomerViewSet(viewsets.ModelViewSet): | ||
| queryset = Customer.objects.all() | ||
| serializer_class = CustomerSerializer | ||
| filterset_class = CustomerFilter | ||
|
|
||
|
|
||
| # Address ViewSet | ||
| class AddressViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = Address.objects.all() | ||
| serializer_class = AddressSerializer | ||
| filterset_class = AddressFilter | ||
| serializer_action_classes = { | ||
| "detailed_list": AddressDetailedSerializer, | ||
| "detailed": AddressDetailedSerializer, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bence bu ve bunun gibi comment'ler kaldirilabilir cunku class isminden anlayabilecegimizden baska extra bir bilgi vermiyor.