Ajout des modeles pour les votes

This commit is contained in:
Yoann Pétri 2018-01-21 01:10:32 +01:00 committed by yoannpietri
parent 3bdfeb3e08
commit 931fff8187
9 changed files with 130 additions and 12 deletions

View file

@ -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)

View 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)),
],
),
]

View 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',
),
]

View 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)),
],
),
]

View file

@ -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,

View file

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'settings', 'settings',
'content', 'content',
'vote'
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View file

@ -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)

View 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'),
),
]

View file

@ -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)
]
) )