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
from django.contrib import admin | |
from .forms import PostAdminForm | |
from .models import Post | |
class PostAdmin(admin.ModelAdmin): | |
form = PostAdminForm | |
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
"""CheckConstraintの使用例""" | |
from django.db import models | |
class Member(models.Model): | |
name = models.CharField(verbose_name="名前", max_length=100) | |
age = models.IntegerField(verbose_name="年齢") | |
class Meta: | |
constraints = [ |
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
"""HttpResponseを使う場合""" | |
import csv | |
from django.contrib import admin | |
from django.http.response import HttpResponse | |
from .models import Book | |
def export_as_csv(modeladmin, request, queryset): |
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
reverse_lazy = lazy(reverse, str) |
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
def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None): | |
if urlconf is None: | |
urlconf = get_urlconf() | |
resolver = get_resolver(urlconf) | |
args = args or [] | |
kwargs = kwargs or {} | |
prefix = get_script_prefix() | |
if not isinstance(viewname, str): |
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
{% load static %} | |
{# users/signin.html #} | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>サインイン- django_webauthn_example</title> | |
</head> | |
<body> | |
<h2>サインイン</h2> |
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
"""users/backends.py""" | |
from django.conf import settings | |
from fido2.server import Fido2Server, RelyingParty | |
from .models import User, WebAuthnPublicKey | |
rp = RelyingParty(settings.RELYING_PARTY_DOMAIN, settings.RELYING_PARTY_NAME) | |
server = Fido2Server(rp) | |
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
{% load static %} | |
{# users/signup.html #} | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>サインアップ- django_webauthn_example</title> | |
</head> | |
<body> | |
<h2>サインアップ</h2> |
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
"""users/forms.py""" | |
from django import forms | |
from .models import User | |
class SignUpForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) |
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
"""users/models.py""" | |
import pickle | |
from django.contrib.auth import models as auth_models | |
from django.db import models | |
class User(auth_models.AbstractUser): | |
"""ユーザー(AUTH_USER_MODELにこれを設定する)""" | |
display_name = models.CharField(max_length=50, verbose_name="表示名") |