Définition des modèles.

This commit is contained in:
Klafyvel 2018-03-24 20:07:17 +01:00
parent fcce939af9
commit 762d736625
2 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,34 @@
# Generated by Django 2.0.3 on 2018-03-24 19:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Link',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField(verbose_name='Lien')),
],
),
migrations.CreateModel(
name='Playlist',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(verbose_name='date')),
],
),
migrations.AddField(
model_name='link',
name='playlist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='player.Playlist', verbose_name='Playlist'),
),
]

View file

@ -1,3 +1,31 @@
from django.db import models from django.db import models
# Create your models here. PK_LENGTH = 23
class Playlist(models.Model):
date = models.DateTimeField(verbose_name="date")
@staticmethod
def reverse_token(token):
return token & ((1 << PK_LENGTH) - 1)
def get_token(self):
return int(self.date.timestamp()) << PK_LENGTH | self.pk
def get_absolute_url(self):
pass
def __str__(self):
return "Playlist " + str(self.get_token())
class Link(models.Model):
url = models.URLField(verbose_name="Lien")
playlist = models.ForeignKey(
Playlist,
on_delete=models.CASCADE,
verbose_name="Playlist",
)
def __str__(self):
return "Link : " + self.url + " of " + str(self.playlist)