parent
ecb493cb51
commit
53ad0e8ce6
@ -1,3 +1,14 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from polls.models import Poll, Vote, Option
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
admin.site.register(
|
||||||
|
Poll,
|
||||||
|
)
|
||||||
|
admin.site.register(
|
||||||
|
Option,
|
||||||
|
)
|
||||||
|
admin.site.register(
|
||||||
|
Vote,
|
||||||
|
)
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
# Generated by Django 5.0.2 on 2024-03-02 02:52
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Poll',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('question', models.TextField(help_text='Question to ask the user', max_length=250)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Option',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('text', models.TextField(help_text='Poll Option', max_length=100)),
|
||||||
|
('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.poll')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Vote',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('option', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.option')),
|
||||||
|
('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.poll')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -1,3 +1,56 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
|
class Poll(
|
||||||
|
models.Model,
|
||||||
|
):
|
||||||
|
question = models.TextField(
|
||||||
|
max_length=250,
|
||||||
|
help_text="Question to ask the user",
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(
|
||||||
|
self,
|
||||||
|
):
|
||||||
|
return f"Poll: {self.question}"
|
||||||
|
|
||||||
|
|
||||||
|
class Option(
|
||||||
|
models.Model,
|
||||||
|
):
|
||||||
|
poll = models.ForeignKey(
|
||||||
|
Poll,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
text = models.TextField(
|
||||||
|
max_length=100,
|
||||||
|
help_text="Poll Option",
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(
|
||||||
|
self,
|
||||||
|
):
|
||||||
|
return f"Option for {self.poll}: {self.text}"
|
||||||
|
|
||||||
|
|
||||||
|
class Vote(
|
||||||
|
models.Model,
|
||||||
|
):
|
||||||
|
user = models.ForeignKey(
|
||||||
|
User,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
poll = models.ForeignKey(
|
||||||
|
Poll,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
option = models.ForeignKey(
|
||||||
|
Option,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(
|
||||||
|
self,
|
||||||
|
):
|
||||||
|
return f"Vote by {self.user} for {self.poll} - Option:{self.option}"
|
||||||
|
Loading…
Reference in new issue