Skip to content

Instantly share code, notes, and snippets.

View timurbakibayev's full-sized avatar

Timur Bakibayev timurbakibayev

  • Neckarwiese
  • Almaty, Kazakhstan
View GitHub Profile
@timurbakibayev
timurbakibayev / admin.py
Created May 24, 2022 08:21
StackedInline Example
from django.contrib import admin
from shop.models import Cart, Item, CartItem
class ItemInline(admin.StackedInline):
model = CartItem
extra = 5
class CartAdmin(admin.ModelAdmin):
@timurbakibayev
timurbakibayev / models.py
Created May 24, 2022 08:13
Cart-Item relationship
from django.db import models
class Item(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(default=0, decimal_places=2, max_digits=10)
def __str__(self):
return f"{self.name}: ${self.price}"
@timurbakibayev
timurbakibayev / main.py
Created February 21, 2022 17:16
dataclasses replace option
import dataclasses
from dataclasses import dataclass
from decimal import Decimal
@dataclass(frozen=True)
class Account:
amount: Decimal
blocked: Decimal
@timurbakibayev
timurbakibayev / main.py
Created February 21, 2022 17:15
first option to mutate
import dataclasses
from dataclasses import dataclass
from decimal import Decimal
@dataclass(frozen=True)
class Account:
amount: Decimal
blocked: Decimal
import pytest
from decimal import Decimal
from main import Account
class TestNormalAccount:
def test_add_amount(self) -> None:
account = Account(
amount=Decimal(10),
blocked=Decimal(0),
@timurbakibayev
timurbakibayev / test_normal.py
Created February 20, 2022 20:30
Testing the normal account
import pytest
from decimal import Decimal
from main import Account
class TestNormalAccount:
def test_add_amount(self) -> None:
account = Account(
amount=Decimal(10),
blocked=Decimal(0),
@timurbakibayev
timurbakibayev / main.py
Created February 20, 2022 20:26
A mutable dataclass
from dataclasses import dataclass
from decimal import Decimal
@dataclass
class Account:
amount: Decimal
blocked: Decimal
def add_amount(self, amount: Decimal) -> None:
from engine.engine import Engine
from gasoline.gasoline import Gasoline, GasPortion
from gaspump.gaspump import GasPump
from pedal.pedal import Pedal
class TestEverythingTogether:
def test_everything_ok(self) -> None:
"""
Here is the scenario:
from gasoline.gasoline import GasPortion, Gasoline
from gaspump.gaspump import GasPump
from pedal.pedal import Pedal
class Benzine(Gasoline):
pass
class TestPedal:
from dataclasses import dataclass
from gasoline.gasoline import GasPortion
from gaspump.gaspump import GasPump
@dataclass
class Pedal:
connected_gas_pump: GasPump