Source code for mg.orga.roll.models
# MG_GPL_HEADER_BEGIN
#
# This file is part of Media Gallery, GNU GPLv2.
#
# Media Gallery is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# Media Gallery is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Media Gallery; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# MG_GPL_HEADER_END
__author__ = "Media Gallery contributors <mg@lists.ssji.net>"
__copyright__ = "(c) 2010"
__credits__ = ["Dimitri Refauvelet", "Nicolas Pouillon"]
from django.db import models
from mg.core.element.models import Element
__all__ = ['Roll']
class Roll(models.Model):
[docs] children = models.ManyToManyField(Element)
name = models.CharField(max_length = 32)
slug = models.SlugField(max_length = 16)
def append(self, elem):
"""
Appends an element to the Roll
:param elem: Element to add to this roll
"""
self.children.add(elem)
def remove(self, elem):
"""
Removes an element form the Roll
:param elem: Element to remove from this roll
"""
self.children.remove(elem)
def get_random_element(self):
try:
return self.children.order_by("?")[0]
except:
return None
def theme(self):
return self.theme_set.all()[0]
def __unicode__(self):
return u"%s"%(self.name)