Implement rating
parent
f299811620
commit
74cdcd9077
@ -1,2 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
class RateArtistForm(forms.Form):
|
||||||
|
rating = forms.ChoiceField(choices=settings.RATING_CHOICES, required=False, widget=forms.RadioSelect)
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
# Generated by Django 4.1.4 on 2022-12-20 21:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import musicrate.vote.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("core", "0004_alter_artist_link_1_alter_artist_link_2"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Participant",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"token",
|
||||||
|
models.CharField(
|
||||||
|
default=musicrate.vote.models.participant_token,
|
||||||
|
max_length=43,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"session",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE, to="core.session"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Rating",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"value",
|
||||||
|
models.CharField(
|
||||||
|
blank=True,
|
||||||
|
choices=[
|
||||||
|
("1", "sehr schlecht"),
|
||||||
|
("2", "ziemlich schlecht"),
|
||||||
|
("3", "schlecht"),
|
||||||
|
("4", "eher schlecht"),
|
||||||
|
("5", "naja"),
|
||||||
|
("6", "ok"),
|
||||||
|
("7", "eher gut"),
|
||||||
|
("8", "gut"),
|
||||||
|
("9", "ziemlich gut"),
|
||||||
|
("10", "sehr gut"),
|
||||||
|
],
|
||||||
|
max_length=2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"artist",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE, to="core.artist"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"participant",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="vote.participant",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name="rating",
|
||||||
|
constraint=models.UniqueConstraint(
|
||||||
|
fields=("artist", "participant"), name="unique_rating"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -1,3 +1,24 @@
|
|||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from secrets import token_urlsafe
|
||||||
|
|
||||||
|
from ..core.models import Artist, Session
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
def participant_token():
|
||||||
|
return token_urlsafe(32)
|
||||||
|
|
||||||
|
class Participant(models.Model):
|
||||||
|
token = models.CharField(max_length=43, default=participant_token, primary_key=True)
|
||||||
|
session = models.ForeignKey(Session, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
class Rating(models.Model):
|
||||||
|
class Meta:
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(fields=['artist', 'participant'], name='unique_rating'),
|
||||||
|
]
|
||||||
|
|
||||||
|
value = models.CharField(max_length=2, blank=True, choices=settings.RATING_CHOICES)
|
||||||
|
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
|
||||||
|
participant = models.ForeignKey(Participant, on_delete=models.CASCADE)
|
||||||
|
Loading…
Reference in New Issue