comparison oembed/models.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/oembed/models.py@368d731af479
children d3f6e9cb1f39
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 Models for the oembed application.
3 """
4 import datetime
5
6 from django.db import models
7
8
9 class Provider(models.Model):
10 """
11 This model described an oEmbed provider.
12 """
13 JSON, XML = range(2)
14 FORMAT_CHOICES = (
15 (JSON, "json"),
16 (XML, "xml"),
17 )
18
19 name = models.CharField(max_length=128)
20 api_endpoint = models.URLField(max_length=255, verbose_name='API endpoint')
21 url_regex = models.CharField(max_length=255, verbose_name='URL regex')
22 format = models.IntegerField(choices=FORMAT_CHOICES)
23
24 def __unicode__(self):
25 return self.name
26
27
28 class Oembed(models.Model):
29 """
30 This model represents stored embedded content retrieved from an oEmbed
31 provider.
32 """
33 PHOTO, VIDEO, LINK, RICH = range(4)
34 MEDIA_TYPE_CHOICES = (
35 (PHOTO, "photo"),
36 (VIDEO, "video"),
37 (LINK, "link"),
38 (RICH, "rich"),
39 )
40
41 url = models.URLField(max_length=255, db_index=True)
42 type = models.IntegerField(choices=MEDIA_TYPE_CHOICES)
43 title = models.CharField(max_length=255, blank=True, default='')
44 width = models.IntegerField()
45 height = models.IntegerField()
46 html = models.TextField()
47 date_added = models.DateTimeField()
48
49 def __unicode__(self):
50 return self.title or self.url
51
52 def save(self, *args, **kwargs):
53 if not self.pk:
54 self.date_added = datetime.datetime.now()
55
56 super(Oembed, self).save(*args, **kwargs)
57