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