Created
April 11, 2017 13:00
-
-
Save ryu22e/349af7f22d333f55d5dc4eebd1607ed8 to your computer and use it in GitHub Desktop.
Django 1.11 LTS 主な変更点まとめ ref: http://qiita.com/ryu22e/items/f97e56ece566d06bb699
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 Book(models.Model): | |
title = models.CharField(max_length=100) | |
author = models.CharField(max_length=100) | |
price = models.IntegerField() | |
class Meta: | |
indexes = [ | |
models.Index(fields=['title', 'author']), | |
models.Index(fields=['price'], name='price_idx'), # インデックスに名前を付けられる | |
] |
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
<input type="range" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}{% if widget.value %} value="{{ widget.value }}"{% endif %}> |
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 import forms | |
class RangeWidget(forms.Widget): | |
template_name = 'forms/widgets/range.html' |
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 import forms | |
from django.forms.utils import flatatt | |
from django.utils.encoding import force_text | |
from django.utils.html import format_html | |
class RangeWidget(forms.Widget): | |
def render(self, name, value, attrs=None): | |
final_attrs = self.build_attrs(attrs, name=name) | |
if value is None: | |
value = '' | |
if value != '': | |
final_attrs['value'] = force_text(value) | |
return format_html('<input type="range"{}>', | |
flatatt(final_attrs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment