2014-01-22 06:43:33 +00:00
|
|
|
from django.contrib.contenttypes.fields import (
|
2015-02-09 18:19:34 +00:00
|
|
|
GenericForeignKey, GenericRelation,
|
2014-01-22 06:43:33 +00:00
|
|
|
)
|
2008-11-13 19:03:44 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-13 21:34:56 +00:00
|
|
|
from django.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-11-13 19:03:44 +00:00
|
|
|
|
2011-09-20 18:16:49 +00:00
|
|
|
|
2008-11-13 19:03:44 +00:00
|
|
|
class Episode(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2011-08-12 14:14:58 +00:00
|
|
|
length = models.CharField(max_length=100, blank=True)
|
|
|
|
author = models.CharField(max_length=100, blank=True)
|
2008-11-13 19:03:44 +00:00
|
|
|
|
2011-09-20 18:16:49 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2008-11-13 19:03:44 +00:00
|
|
|
class Media(models.Model):
|
|
|
|
"""
|
|
|
|
Media that can associated to any object.
|
|
|
|
"""
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 06:43:33 +00:00
|
|
|
content_object = GenericForeignKey()
|
2012-03-31 13:55:03 +00:00
|
|
|
url = models.URLField()
|
2011-08-12 14:14:58 +00:00
|
|
|
description = models.CharField(max_length=100, blank=True)
|
|
|
|
keywords = models.CharField(max_length=100, blank=True)
|
2008-11-13 19:03:44 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-11-13 19:03:44 +00:00
|
|
|
return self.url
|
|
|
|
|
2009-04-18 20:12:53 +00:00
|
|
|
|
2010-01-21 01:40:21 +00:00
|
|
|
#
|
|
|
|
# Generic inline with unique_together
|
|
|
|
#
|
2010-11-13 18:42:31 +00:00
|
|
|
class Category(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2011-09-20 18:16:49 +00:00
|
|
|
|
2010-01-21 01:40:21 +00:00
|
|
|
class PhoneNumber(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 06:43:33 +00:00
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|
2010-01-21 01:40:21 +00:00
|
|
|
phone_number = models.CharField(max_length=30)
|
2010-11-13 18:42:31 +00:00
|
|
|
category = models.ForeignKey(Category, null=True, blank=True)
|
2010-01-21 01:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = (('content_type', 'object_id', 'phone_number',),)
|
|
|
|
|
2011-09-20 18:16:49 +00:00
|
|
|
|
2010-01-21 01:40:21 +00:00
|
|
|
class Contact(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2014-01-22 06:43:33 +00:00
|
|
|
phone_numbers = GenericRelation(PhoneNumber)
|
2010-01-21 01:40:21 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-02-23 17:14:50 +00:00
|
|
|
#
|
|
|
|
# Generic inline with can_delete=False
|
|
|
|
#
|
|
|
|
class EpisodePermanent(Episode):
|
|
|
|
pass
|