銀行マスター

django-import-export で 銀行マスターを取り込む 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 from import_export import resources from .. import models class BankCodeResource(resources.ModelResource): class Meta: model = models.BankCode import_id_fields = ["code", "branch_code"] fields = ["code", "branch_code", "kana", "name", "branch_kana", "branch_name"] def before_import_row(self, row, row_number=None, **kwargs): for field in self._meta.fields: # ヘッダーは verbose_name に合わせている value = row.pop(self._meta.model._meta.get_field(field).verbose_name, None) if value is None: continue # コードは0埋めする if field == "code": value = str(value).zfill(4) elif field == "branch_code": value = str(value).zfill(3) row[field] = value

2023年6月8日 · 1 分

ijavascript

ijavascript https://n-riesco.github.io/ijavascript/index.html

2023年6月7日 · 1 分

HTML メール

HTML メール HTML メールの作り方を 5 分で解説!簡単に作成する方法もこっそり教えます。

2023年6月5日 · 1 分

color

HTML カラーコード/カラーネーム HTML カラーコード CSS カラーコード一覧 カラーネーム CSS3 色名 VSCode Peacock VSCode を自分の好きな色に染める

2023年6月1日 · 1 分

django session

Sessionのユーザーの取得 Djangoでセッションレコードがどのユーザーのものかを判定するには、以下のようにします。 1 2 3 4 5 6 7 8 from django.contrib.sessions.models import Session from django.contrib.auth.models import User for session in Session.objects.all(): uid = session.get_decoded().get('_auth_user_id') if uid: user = User.objects.get(id=uid) print(user.username) 参考文献: Django ドキュメント | セッションの使いかた ソース: Bing との会話 2023/5/30 (1) セッションの使いかた | Django ドキュメント | Django. https://docs.djangoproject.com/ja//2.2/topics/http/sessions/. (2) 【Django】ログイン判定機能の実装方法を実例付きで徹底解説. https://itc.tokyo/django/dynamic-links-by-user-info/. (3) Djangoで現在ログインしているユーザーのユーザーIDを取得する方法. https://qastack.jp/programming/12615154/how-to-get-the-currently-logged-in-users-user-id-in-django. SessionStoreをつかう 1 2 3 4 5 6 7 from django.contrib.sessions.backends.db import SessionStore key = "3gsbhdfm4g2uyyieaaxl1omor2p5f1on" store = SessionStore(session_key=key) store["ssout_required"] = True store.save()

2023年5月30日 · 1 分

Puppeteer

Puppeteer Puppeteer とヘッドレス Chrome を使って React の SPA サイトをクロールするためのスクリプトを記述するには、以下のようなコードを記述することができます ¹。 1 2 3 4 5 6 7 8 9 10 11 12 const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto("https://example.com"); // SPA のページ遷移を待つ await page.waitForNavigation({ waitUntil: "networkidle0" }); // スクリーンショットを撮る await page.screenshot({ path: "example.png" }); await browser.close(); })(); 上記のコードでは、Puppeteer を使ってブラウザを起動し、指定した URL にアクセスしています。その後、SPA のページ遷移が完了するまで待機し、スクリーンショットを撮影しています。必要に応じて、このコードを改良していただければと思います。 ...

2023年5月23日 · 1 分

django-import-export

django-import-export django-import-export = "^2.4.0" settings.py 1 2 3 4 5 INSTALLED_APPS += [ ... "import_export", ... ] resources.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 from import_export import resources from .. import models class DepartmentResource(resources.ModelResource): class Meta: model = models.Department import_id_fields = ["code", "company_code"] # 複合キー exclude = ["company", "jobposts", "origin", "status"] # 除外 def get_instance(self, instance_loader, row): instance = super().get_instance(instance_loader, row) exclude = [] if instance: exclude += ["is_m03", "is_tmb"] # 更新除外 list(map(lambda i: row.pop(i, None), exclude)) return instance admin.py 1 2 3 4 5 6 7 8 9 10 11 12 13 from import_export.admin import ImportExportActionModelAdmin from . import inlines, resources class BaseModelAdmin(ImportExportActionModelAdmin): exclude = ["created_at"] readonly_fields = ["updated_at"] @admin.register(models.Department) class DepartmentAdmin(BaseModelAdmin): ... resource_class = resources.DepartmentResource

2023年5月18日 · 1 分

Headless CMS

Headless CMS 【2023年】人気のヘッドレスCMSを徹底比較!Contentful・Strapi・Hygraphなど。

2023年5月18日 · 1 分

Django Subquery

Subquery 合計値のアノテート サブクエリの合計値: 合計対象レコードを OuterRefで条件指定してして絞り込む values() で ユニークフィールドで GROUP BY する 対象フィールドの合計値をanotate する アノテートしたフィールドを values() で ValueList にしてSubqueryで返す(1件のはず) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 def verify(): from django.db.models import OuterRef, Subquery, F from django.db.models.functions import Coalesce from base.models.utils import aggr_sum_decimal as D from decimal import Decimal ref_query = dict( book__company_code=OuterRef("company_code"), book__processing_month=OuterRef("processing_month"), account_code=OuterRef("account_code"), account_item_code=OuterRef("account_item_code"), advances_code=OuterRef("outsource_code"), advances_branch_code=OuterRef("outsource_branch_code"), ) def bookitem_sum(bookitem): qs = ( bookitem.objects.filter(**ref_query) .values(*ref_query.keys()) .annotate(total=D("amount")) .values("total") ) return Subquery(qs) qs = models.CostOutsource.objects.annotate( sum_debit=Coalesce(bookitem_sum(BookDebit), Decimal("0")), sum_credit=Coalesce(bookitem_sum(BookCredit), Decimal("0")), ).exclude(debit_amount=F("sum_debit"), credit_amount=F("sum_credit")) Bing Djangoのクエリセットで、別のテーブルのフィールドの合計値をSubqueryを使ってannotateすることができます¹。以下は、例です。 ...

2023年5月17日 · 1 分

DRF: Content Negotiation

DRF: Content Negotiation DefaultContentNegotiation content_negotiation_classをカスタマイズするには、以下のようにします。 1 2 3 4 5 6 from rest_framework.negotiation import DefaultContentNegotiation class MyContentNegotiation(DefaultContentNegotiation): def select_renderer(self, request, renderers, format_suffix=None): # ここに処理を書きます。 pass 上記の例では、DefaultContentNegotiationを継承しています。 select_renderer()メソッドには、レンダラーを選択するための処理を書きます。 このメソッドは、リクエストオブジェクト、レンダラーのリスト、およびフォーマットサフィックスを引数として受け取ります。 ソース: Bing との会話 2023/5/12 (1) Content negotiation - Django REST framework. https://www.django-rest-framework.org/api-guide/content-negotiation/. (2) Django REST Framework - Content negotiation - HTTPは …. https://runebook.dev/ja/docs/django_rest_framework/api-guide/content-negotiation/index. (3) Django REST framework カスタマイズ方法 - チュートリアルの補足. https://qiita.com/okoppe8/items/c58bb3faaf26c9e2f27f. ViewSetでの設定 ViewSetごとにcontent_negotiation_classを設定することができます。 ...

2023年5月12日 · 1 分