source: telemeta/models.py @ 6d9a741

cremcrem2crem3devdev2diademsdj1.6feature/breadcrumbsfeature/ts-0.5feature/ts-0.5.4feature/writecacheformagenericinstru_searchlamlam2mapsv3mergenlivemultiproductionrelease/1.4.4sabiodsearchsecurityserversocialstoragetelecastertestvideo
Last change on this file since 6d9a741 was 6d9a741, checked in by olivier <>, 8 years ago
  • coupled the web interface with the export layer
  • improved collections and items browsing
  • minor CSS improvements
  • now using Django typical models instead of "dynamic" ones
  • made simple models based on Dublin Core elements
  • Property mode set to 100644
File size: 3.8 KB
Line 
1import telemeta
2from django.db import models
3from telemeta.core import *
4
5class MediaModel(Component):
6    pass
7
8class MediaCore:
9    def list(self):
10        fields_list = []
11        for field in self._meta.fields:
12            fields_list.append({'name': field.name, 'value': getattr(self, field.name)})
13        return fields_list
14
15    def to_dict(self):       
16        fields_dict = {}
17        for field in self._meta.fields:
18            fields_dict[field.name] = getattr(self, field.name)
19        return fields_dict
20
21class MediaCollection(models.Model, MediaCore):
22    "Group related media items"
23
24    title = models.CharField(maxlength=250)
25    date = models.DateField()
26    contributor = models.CharField(maxlength=250, blank=True)
27    coverage = models.CharField(maxlength=250, blank=True)
28    creator = models.CharField(maxlength=250, blank=True)
29    description = models.CharField(maxlength=250, blank=True)
30    format = models.CharField(maxlength=250, blank=True)
31    identifier = models.CharField(maxlength=250, blank=True)
32    language = models.CharField(maxlength=250, blank=True)
33    publisher = models.CharField(maxlength=250, blank=True)
34    rights = models.CharField(maxlength=250, blank=True)
35    source = models.CharField(maxlength=250, blank=True)
36    subject = models.CharField(maxlength=250, blank=True)
37
38    def __str__(self):
39        return self.title
40
41    class Meta:
42        ordering = ['title']
43        db_table = 'telemeta_collection'
44
45    class Admin:
46        pass
47
48
49
50class MediaItem(models.Model, MediaCore):
51    "Describe a item with metadata" 
52
53    collection = models.ForeignKey(MediaCollection, related_name="items")
54    collection.dublin_core = 'relation'
55    identifier = models.CharField(maxlength=250)
56    title = models.CharField(maxlength=250)
57    creator = models.CharField(maxlength=250)
58    date = models.DateField()
59    file = models.FileField(upload_to='items/%Y/%m/%d')
60    subject = models.CharField(maxlength=250, blank=True)
61    description = models.TextField(maxlength=250, blank=True)
62    contributor = models.CharField(maxlength=250, blank=True)
63    coverage = models.CharField(maxlength=250, blank=True)
64    format = models.CharField(maxlength=25, blank=True)
65    language = models.CharField(maxlength=250, blank=True)
66    publisher = models.CharField(maxlength=250, blank=True)
67    rights = models.CharField(maxlength=250, blank=True)
68    source = models.CharField(maxlength=250, blank=True)
69    duration = models.FloatField(max_digits=11, decimal_places=3, null=True, blank=True)
70
71    def __str__(self):
72        return self.title
73
74    class Admin:
75        pass
76
77    class Meta:
78        ordering = ['title']
79        db_table = 'telemeta_item'
80
81
82class MediaPart(models.Model, MediaCore):
83    "Describe the part of a media item"
84
85    contributor = models.CharField(maxlength=250)
86    coverage = models.CharField(maxlength=250)
87    creator = models.CharField(maxlength=250)
88    date = models.DateField()
89    description = models.CharField(maxlength=250)
90    format = models.CharField(maxlength=250)
91    identifier = models.CharField(maxlength=250)
92    language = models.CharField(maxlength=250)
93    publisher = models.CharField(maxlength=250)
94    rights = models.CharField(maxlength=250)
95    source = models.CharField(maxlength=250)
96    subject = models.CharField(maxlength=250)
97    title = models.CharField(maxlength=250)
98    media_item = models.ForeignKey(MediaItem)
99    media_item.dublin_core = 'relation'
100    parent = models.ForeignKey('self', null=True, related_name='children')
101    media_item.dublin_core = 'relation'
102    start = models.FloatField(max_digits=11, decimal_places=3)
103    end = models.FloatField(max_digits=11, decimal_places=3)
104
105    def __str__(self):
106        return self.title
107
108    class Meta:
109        ordering = ['title']
110        db_table = 'telemeta_part'
111
112    class Admin:
113        pass
114
115
Note: See TracBrowser for help on using the repository browser.