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
Ertugrulbal hw 3 #77
Open
Ertugrulbal
wants to merge
5
commits into
upy:main
Choose a base branch
from
Ertugrulbal:ertugrulbal-hw-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
Ertugrulbal hw 3 #77
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7dbbc60
customers' models serializers was created and checked at localhost/api
Ertugrulbal 5aa1dfa
Basket app models' serializers was created and checked at localhos/api
Ertugrulbal b48e21c
payments and orders' serializer files was created and checked at loca…
Ertugrulbal 83a07a9
Orders app's serializers, filters, viewsets were created and attached…
Ertugrulbal 82220e3
The last controls was done and added README File
Ertugrulbal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,9 @@ | ||
| ### Core | ||
|
|
||
| It contains functions, classes and constants to be used as a basis in the core. | ||
|
|
||
| ### Customers | ||
|
|
||
| It contains customer model and address model for customers. | ||
|
|
||
| ### Products | ||
|
|
||
| It contains product model, category model, stock model and price model for products. | ||
|
|
||
| ### Baskets | ||
|
|
||
| It contains basket model and basket item in basket model. | ||
|
|
||
| ### Orders | ||
|
|
||
| It contains billing address model, shipping address model, order bank account model, order model and order item model. | ||
|
|
||
| ### Payments | ||
|
|
||
| It contains bank model and bank account model. | ||
| ## All models' serializers, filters, viewsets was created, these are; | ||
| 1- Baskets | ||
| 2- Customers | ||
| 3- Orders | ||
| 4- Payments | ||
| 5- Products | ||
| ## Also all models' serializer roots was created at the ecommerce/urls.py | ||
|
|
||
| ## Pagination was added to ecommerce/settings.py | ||
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,13 @@ | ||
| from django.db.models import Q | ||
| from django_filters import rest_framework as filters | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from baskets.models import Basket | ||
|
|
||
|
|
||
| class BasketFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("Name"), method="") | ||
|
Owner
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. eksik kalmis sanki? |
||
|
|
||
| class Meta: | ||
| model = Basket | ||
| fields = ("customer", ) | ||
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,22 @@ | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
| from baskets.models import Basket, BasketItem | ||
|
|
||
|
|
||
|
|
||
| class BasketSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Basket | ||
| fields = ("customer", "status") | ||
|
|
||
|
|
||
| class BasketItemSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = BasketItem | ||
| fields = ("basket", "product","quantity","price" ) | ||
|
Owner
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. id eklememizde fayda var. |
||
|
|
||
| class BasketItemDetailedSerializer(BasketItemSerializer): | ||
| basket = BasketSerializer() | ||
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,20 @@ | ||
| from django.shortcuts import render | ||
| from rest_framework import viewsets | ||
|
|
||
| # Create your views here. | ||
| from core.mixins import DetailedViewSetMixin | ||
| from baskets.filters import BasketFilter | ||
| from baskets.models import Basket, BasketItem | ||
| from baskets.serializers import BasketSerializer, BasketItemSerializer, BasketItemDetailedSerializer | ||
|
|
||
| class BasketViewSet(viewsets.ModelViewSet): | ||
| queryset = Basket.objects.all() | ||
| serializer_class = BasketSerializer | ||
| filterset_class = BasketFilter | ||
|
|
||
| class BasketItemViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = BasketItem.objects.all() | ||
| serializer_class = BasketItemSerializer | ||
|
|
||
|
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.
serializer_action_classes = {
"detailed_list": BasketDetailedSerializer,
"detailed": BasketDetailedSerializer,
} |
||
| class BasketItemDetailedViewSet(viewsets.ModelViewSet): | ||
| queryset = BasketItem.objects.all() | ||
| serializer_class = BasketItemDetailedSerializer | ||
| http_method_names = ["get"] | ||
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,18 @@ | ||
|
|
||
| from django_filters import rest_framework as filters | ||
| from customers.models import Customer, Address | ||
|
|
||
|
|
||
|
|
||
|
|
||
| class CustomerFilter(filters.FilterSet): | ||
|
|
||
| class Meta: | ||
| model = Customer | ||
| fields = ("is_active", "is_staff") | ||
|
|
||
| class AddressFilter(filters.FilterSet): | ||
|
|
||
| class Meta: | ||
| model = Address | ||
| fields = ("name", "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,46 @@ | ||
| from django.db.transaction import atomic | ||
| from rest_framework import serializers | ||
| from customers.models import Customer, Address, City, Country | ||
|
|
||
| class CustomerSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Customer | ||
| fields = ("first_name", "last_name", "email") | ||
|
|
||
| class AddressSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Address | ||
| fields = ("customer", "name", "full_name", "line_1","line_2","phone","district","zipcode","city") | ||
|
|
||
|
|
||
| class CountrySerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Country | ||
| fields = ("name", ) | ||
|
|
||
| class CitySerializer(serializers.ModelSerializer): | ||
| country = CountrySerializer() | ||
| class Meta: | ||
| model = City | ||
| fields = ("name", "country") | ||
|
|
||
| class AddressDetailedSerializer(AddressSerializer): | ||
| customer = CustomerSerializer() | ||
| city = CitySerializer() | ||
|
|
||
|
|
||
| @atomic() | ||
| def create(self, validated_data): | ||
| customers = validated_data.pop("customers", None) | ||
| address = super().create(validated_data) | ||
| if customers: | ||
| serializer = CustomerSerializer(data=addresses, many=True) | ||
| serializer.is_valid(raise_exception=True) | ||
| serializer.save() | ||
| address.customers.add(*serializer.instance) | ||
|
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. Customer ile Address arasında 1-M ilişki var. address modelinin customers adında bir fieldı yok. |
||
| return address | ||
|
|
||
|
|
||
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,32 @@ | ||
| from django.shortcuts import render | ||
| from rest_framework import viewsets | ||
| from core.mixins import DetailedViewSetMixin | ||
|
|
||
| # Create your views here. | ||
|
|
||
| from customers.filters import CustomerFilter, AddressFilter | ||
| from customers.models import Customer, Address, City, Country | ||
| from customers.serializers import CustomerSerializer, AddressSerializer, CitySerializer, CountrySerializer, \ | ||
| AddressDetailedSerializer | ||
|
|
||
|
|
||
| class CustomerViewSet(viewsets.ModelViewSet): | ||
| queryset = Customer.objects.all() | ||
| serializer_class = CustomerSerializer | ||
| filterset_class = CustomerFilter | ||
|
|
||
| class AddressViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = Address.objects.all() | ||
| serializer_class = AddressSerializer | ||
| filterset_class = AddressFilter | ||
|
|
||
| class AddressDetailedViewSet(viewsets.ModelViewSet): | ||
| queryset = Address.objects.all() | ||
| serializer_class = AddressDetailedSerializer | ||
| http_method_names = ["get"] | ||
|
|
||
| class CityViewSet(viewsets.ModelViewSet): | ||
| queryset = City.objects.all() | ||
| serializer_class = CitySerializer | ||
|
|
||
| class CountryViewSet(viewsets.ModelViewSet): | ||
| queryset = Country.objects.all() | ||
| serializer_class = CountrySerializer |
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
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,13 @@ | ||
|
|
||
| from django_filters import rest_framework as filters | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from orders.models import Order | ||
|
|
||
|
|
||
| class OrderFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("Name"), method="") | ||
|
|
||
| class Meta: | ||
| model = Order | ||
| fields = ("customer", "status") |
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,42 @@ | ||
| from rest_framework import serializers | ||
|
|
||
| from orders.models import Order, OrderItem, OrderBankAccount, ShippingAddress, BillingAddress | ||
| from customers.serializers import CustomerSerializer | ||
| from baskets.serializers import BasketSerializer | ||
|
|
||
| class BillingAddressSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = BillingAddress | ||
| fields = ("full_name", "line_1", "line_2", "phone","district", "zipcode", "city") | ||
|
|
||
| class ShippingAddressSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = ShippingAddress | ||
| fields = ("full_name", "line_1", "line_2", "phone","district", "zipcode", "city") | ||
|
|
||
| class OrderBankAccountSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = OrderBankAccount | ||
| fields = ("name", "iban", "bank_name", "order") | ||
|
|
||
| class OrderSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Order | ||
| fields = ("customer", "basket","status","billing_address", "shipping_address","total_price" ) | ||
|
|
||
|
|
||
| class OrderItemSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = OrderItem | ||
| fields = ("order", "product","price" ) | ||
|
|
||
| class OrderDetailedSerializer(OrderSerializer): | ||
| billing_address = BillingAddressSerializer() | ||
| shipping_address = ShippingAddressSerializer() | ||
| customer = CustomerSerializer() | ||
| basket = BasketSerializer() |
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,33 @@ | ||
| from django.shortcuts import render | ||
| from rest_framework import viewsets | ||
| from core.mixins import DetailedViewSetMixin | ||
| from orders.filters import OrderFilter | ||
| from orders.models import Order, OrderItem, OrderBankAccount, ShippingAddress, BillingAddress | ||
| from orders.serializer import OrderSerializer, OrderItemSerializer, OrderBankAccountSerializer, BillingAddressSerializer, ShippingAddressSerializer, \ | ||
| OrderDetailedSerializer | ||
|
|
||
| # Create your views here. | ||
|
|
||
| class OrderViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| queryset = Order.objects.all() | ||
| filterset_class = OrderFilter | ||
| serializer_class = OrderSerializer | ||
|
|
||
| class OrderBankAccountViewSet(viewsets.ModelViewSet): | ||
| queryset = OrderBankAccount.objects.all() | ||
| serializer_class = OrderBankAccountSerializer | ||
|
|
||
| class OrderItemViewSet(viewsets.ModelViewSet): | ||
| queryset = OrderItem.objects.all() | ||
| serializer_class = OrderItemSerializer | ||
|
|
||
| class ShippingAddressViewSet(viewsets.ModelViewSet): | ||
| queryset = ShippingAddress.objects.all() | ||
| serializer_class = ShippingAddressSerializer | ||
|
|
||
| class BillingAddressViewSet(viewsets.ModelViewSet): | ||
| queryset = BillingAddress.objects.all() | ||
| serializer_class = BillingAddressSerializer | ||
|
|
||
| class OrderDetailedViewSet(viewsets.ModelViewSet): | ||
| queryset = Order.objects.all() | ||
| serializer_class = OrderDetailedSerializer | ||
| http_method_names = ["get"] |
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,13 @@ | ||
|
|
||
| from django_filters import rest_framework as filters | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from payments.models import BankAccount | ||
|
|
||
|
|
||
| class BankAccountFilter(filters.FilterSet): | ||
| name = filters.CharFilter(label=_("Name"), method="") | ||
|
|
||
| class Meta: | ||
| model = BankAccount | ||
| fields = ("bank",) |
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,21 @@ | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
| from payments.models import Bank, BankAccount | ||
|
|
||
|
|
||
| class BankSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = Bank | ||
| fields = ("name", ) | ||
|
|
||
|
|
||
| class BankAccountSerializer(serializers.ModelSerializer): | ||
|
|
||
| class Meta: | ||
| model = BankAccount | ||
| fields = ("bank", "name", "iban") | ||
|
|
||
| class BankAccountDetailedSerializer(BankAccountSerializer): | ||
| bank = BankSerializer() |
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.