coding utf-8 from django db import models from pytils translit import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# coding: utf-8
from django.db import models
from pytils.translit import slugify
class Genres(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField(max_length=20, blank=True)
class Meta:
ordering = ['title']
verbose_name = "genre"
verbose_name_plural = "genres"
def __unicode__(self):
return self.title
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Genres, self).save(*args, **kwargs)
class Directors(models.Model):
name = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, blank=True)
class Meta:
ordering = ['name']
verbose_name = "director"
verbose_name_plural = "directors"
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Directors, self).save(*args, **kwargs)
class Actors(models.Model):
name = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, blank=True)
class Meta:
ordering = ['name']
verbose_name = "actor"
verbose_name_plural = "actors"
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Actors, self).save(*args, **kwargs)
class Film(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, blank=True)
released_date = models.DateField()
genre = models.ManyToManyField(Genres)
director = models.ForeignKey(Directors)
actors = models.ManyToManyField(Actors)
actors_as_text = models.CharField(max_length=250)
description = models.TextField()
class Meta:
verbose_name = "film"
verbose_name_plural = "films"
def __unicode__(self):
return '%s (%s)' % (self.title, self.director)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
act = self.actors.all()
if act.count > 0:
self.actors_as_text = " ".join([actor.name for actor in act])
super(Film, self).save(*args, **kwargs)