This file contains 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
from typing import Optional, Any, Dict, TYPE_CHECKING | |
from pydantic import BaseModel, validator, validate_model, PrivateAttr | |
from pydantic.error_wrappers import ValidationError | |
object_setattr = object.__setattr__ | |
class Foobar(BaseModel): | |
_errors = PrivateAttr() |
This file contains 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
<template> | |
<div id="app"> | |
<button @click="load">Load Component right here.</button> | |
<async-component | |
v-if="loadComponent" | |
:component="Example" | |
example="Example Props" | |
@listen="listen"/> | |
</div> | |
</template> |
This file contains 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
<template> | |
<transition name="fade" mode="out-in"> | |
<component | |
ref="asyncComponent" | |
:is="asyncComponent" | |
v-bind.sync="$attrs" | |
@reload="getComponent" | |
v-on="$listeners" | |
/> | |
</transition> |
This file contains 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
from django.db.models import Count, Q | |
q2 = Exam.objects.aggregate( | |
success=Count("pk", filter=Q(score__gte=85)), | |
) | |
print(q) | |
# {"success": 5} |
This file contains 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
from django.db.models import Case, IntegerField, Sum, Value, When | |
from django.db.models.functions import Coalesce | |
q = Exam.objects.aggregate( | |
success=Coalesce( | |
Sum( | |
Case( | |
When(score__gte=85, then=Value(1)), | |
default=Value(0), | |
output_field=IntegerField(), |
This file contains 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
from django.db import models | |
class Exam(models.Model): | |
studen_name = models.CharField(max_lenght=50) | |
point = models.PositiveIntegerField(default=0) | |
This file contains 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
def gcd(x, y): | |
while y != 0: | |
(x, y) = (y, x % y) | |
return x |
This file contains 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
from sys import getsizeof | |
import json | |
import timeit | |
j = '''{ | |
"first_name": "Mazlum", | |
"last_name": "Ağar" | |
}''' | |
# Memory |
This file contains 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
# views.py | |
def product_list(request): | |
f = ProductFilter(request.GET, queryset=Product.objects.all()) | |
return render(request, 'my_app/template.html', {'filter': f}) | |
# urls.py | |
from django.conf.urls import url | |
from django_filters.views import FilterView | |
from myapp.models import Product |
This file contains 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
class ContentTypesConfig(AppConfig): | |
name = 'django.contrib.contenttypes' | |
verbose_name = _("Content Types") | |
def ready(self): | |
pre_migrate.connect(inject_rename_contenttypes_operations, sender=self) | |
post_migrate.connect(create_contenttypes) | |
checks.register(check_generic_foreign_keys, checks.Tags.models) | |
checks.register(check_model_name_lengths, checks.Tags.models) |
NewerOlder