Ajout des modeles pour les votes
This commit is contained in:
parent
3bdfeb3e08
commit
931fff8187
9 changed files with 130 additions and 12 deletions
|
@ -1,6 +1,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Category, Content
|
from .models import Category, Content, School, Video
|
||||||
|
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
admin.site.register(Content)
|
admin.site.register(Content)
|
||||||
|
admin.site.register(School)
|
||||||
|
admin.site.register(Video)
|
||||||
|
|
20
content/migrations/0002_ecole.py
Normal file
20
content/migrations/0002_ecole.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-01-20 23:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Ecole',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
17
content/migrations/0003_auto_20180120_2352.py
Normal file
17
content/migrations/0003_auto_20180120_2352.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-01-20 23:52
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0002_ecole'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='Ecole',
|
||||||
|
new_name='School',
|
||||||
|
),
|
||||||
|
]
|
20
content/migrations/0004_video.py
Normal file
20
content/migrations/0004_video.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-01-21 00:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0003_auto_20180120_2352'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Video',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,6 +9,18 @@ class Category(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class School(models.Model):
|
||||||
|
name = models.CharField(
|
||||||
|
max_length=255
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Video(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
|
||||||
class Content(models.Model):
|
class Content(models.Model):
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
|
|
|
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'settings',
|
'settings',
|
||||||
'content',
|
'content',
|
||||||
|
'vote'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import Vote, Voter
|
||||||
|
|
||||||
# Register your models here.
|
admin.site.register(Vote)
|
||||||
|
admin.site.register(Voter)
|
||||||
|
|
42
vote/migrations/0001_initial.py
Normal file
42
vote/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-01-21 00:07
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0004_video'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Vote',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('vote', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])),
|
||||||
|
('categorie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='content.Category')),
|
||||||
|
('video', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='content.Video')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Voter',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=100)),
|
||||||
|
('firstname', models.CharField(max_length=100)),
|
||||||
|
('email', models.EmailField(max_length=200)),
|
||||||
|
('password', models.CharField(max_length=100)),
|
||||||
|
('ecole', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='content.School')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vote',
|
||||||
|
name='votant',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vote.Voter'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,23 +1,25 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
|
from content.models import School, Category, Video
|
||||||
|
|
||||||
|
class Voter(models.Model):
|
||||||
class Votants(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
firstname = models.CharField(max_length=100)
|
firstname = models.CharField(max_length=100)
|
||||||
email = models.EmailField(max_length=200)
|
email = models.EmailField(max_length=200)
|
||||||
ecole = models.ForeignKey(Ecole, on_delete=models.CASCADE)
|
ecole = models.ForeignKey('content.School', on_delete=models.CASCADE)
|
||||||
password = models.CharField(max_length=100)
|
password = models.CharField(max_length=100)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.firstname + " " + self.name
|
return self.firstname + " " + self.name
|
||||||
|
|
||||||
class Votes(models.Model):
|
|
||||||
votant = models.ForeignKey(Votants, on_delete = models.CASCADE)
|
class Vote(models.Model):
|
||||||
video = models.ForeignKey(Videos, on_delete = models.CASCADE)
|
votant = models.ForeignKey('Voter', on_delete=models.CASCADE)
|
||||||
categorie = models.ForeignKey(Categories, on_delete = models.CASCADE)
|
video = models.ForeignKey('content.Video', on_delete=models.CASCADE)
|
||||||
|
categorie = models.ForeignKey('content.Category', on_delete=models.CASCADE)
|
||||||
vote = models.IntegerField(
|
vote = models.IntegerField(
|
||||||
min_value = 0,
|
validators=[
|
||||||
max_value = 5,
|
validators.MaxValueValidator(5),
|
||||||
validators = [validators.MaxValueValidator(5),validators.MinValueValidator(0)]
|
validators.MinValueValidator(0)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue