django-lookup-table-rating-widget
A django rating widget with a lookup-table for score-making rules.
Install
pip install django-lookup-table-rating-widget
Usage
pro/settings.py
Note:
- We used template of django-lookup-table-rating-widget, so we NEED add django_lookup_table_rating_widget in INSTALLED_APPS.
INSTALLED_APPS = [
...
'django_lookup_table_rating_widget',
...
]
app/admin.py
from django.contrib import admin
from django.utils.lorem_ipsum import sentence
from django_lookup_table_rating_widget.widgets import DjangoLookupTableRatingWidget
from django import forms
from .models import Book
s1_scores = [
{
"scores": [1, 2],
"rule": "<b>Bad</b>. " + sentence(),
},{
"scores": [3, 4],
"rule": "<b>Not bad</b>. " + sentence(),
},{
"scores": [5, 6],
"rule": "<b>Good</b>. " + sentence(),
},{
"scores": [7, 8],
"rule": "<b>Very Good</b>." + sentence(),
},{
"scores": [9, 10],
"rule": "<b>Excellent</b>." + sentence(),
}
]
class BookForm(forms.ModelForm):
class Meta:
model = Book
exclude = []
widgets = {
"s1": DjangoLookupTableRatingWidget(s1_scores, field_label_in_table=False, weight=15),
"s2": DjangoLookupTableRatingWidget(s1_scores, allow_input=True),
"s3": DjangoLookupTableRatingWidget(s1_scores),
"s4": DjangoLookupTableRatingWidget(s1_scores),
}
class BookAdmin(admin.ModelAdmin):
form = BookForm
list_display = ["title"]
fieldsets = [
(None, {
"fields": ["title"]
}),
("Score 1 & 2", {
"fields": ["s1", "s2"],
}),
("Score 3 & 4", {
"fields": ["s3", "s4"],
})
]
admin.site.register(Book, BookAdmin)
Widget Init Parameters
scores: required.- It's a list of map. The map always contains
scoresandruleitem.scoresis a list of rating buttons, and theruleis a string of rule description. HTMLruleis accepted.
- It's a list of map. The map always contains
allow_input: optional, default to False.- If allow_input=True, the final score input is allowed to input.
- If allow_input=False, the final score input is readonly.
field_label_in_table: optional, default True.- If field_label_in_table=True, we use jquery to move field's label and help into the table.
- If field_label_in_table=False, we keep the field's label and help at thire original position.
weight: optional, default None.- weight means the field weight in full rating form.
- If not provides, we will remove the weight column.
field_label: optional, default to _("Item").final_score_label: optional, default to _("Score").scores_label: optional, default to _("Rating Buttons").rules_label: optional, default to _("Rule").weight_label: _("Weight").- All lables are used to render the rating table header.
Releases
v0.1.1 2020/09/25
- No depends on django_static_jquery3.
- Add license file.
v0.1.0 2020/03/18
- First release.
Release files for django-lookup-table-rating-widget 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-lookup-table-rating-widget-0.1.1.tar.gz | 7.8 kB | Details |
Release files / django-lookup-table-rating-widget-0.1.1.tar.gz
| Download URL | django-lookup-table-rating-widget-0.1.1.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77e7ade04ff55a86d2726ac4504d77883f240d8895e24236a527b7be4132454e
|
|
BLAKE2b-256 checksum How to use checksums |
a1a86a587cd5f18bc779da9eb1e6d0826313a417f0c0f0a6f73077f06e9204d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8
|