summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a89a32991..90232159c 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2014 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -41,6 +41,8 @@ from django.utils.safestring import SafeUnicode, mark_safe
from django.template.defaultfilters import slugify
from django.contrib.auth.models import User, Group
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes import generic
from django.contrib.gis.db import models
from django.contrib import admin
@@ -351,6 +353,34 @@ class GeneralType(models.Model):
self.txt_idx = slugify(self.label)
return super(GeneralType, self).save(*args, **kwargs)
+ def get_keys(self):
+ keys = []
+ content_type = ContentType.objects.get_for_model(self.__class__)
+ for ik in ItemKey.objects.filter(content_type=content_type,
+ object_id=ik.pk).all():
+ keys.append(ik.key)
+ return keys
+
+ @classmethod
+ def generate_keys(cls):
+ content_type = ContentType.objects.get_for_model(cls)
+ for item in cls.objects.all():
+ for key in (slugify(item.label), item.txt_idx):
+ if not ItemKey.objects.filter(object_id=item.pk, key=key,
+ content_type=content_type).count():
+ ik = ItemKey(object_id=item.pk, key=key,
+ content_type=content_type)
+ ik.save()
+
+class ItemKey(models.Model):
+ key = models.CharField(_(u"Key"), max_length=100)
+ content_type = models.ForeignKey(ContentType)
+ object_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey('content_type', 'object_id')
+
+ def __unicode__(self):
+ return self.key
+
class ImageModel(models.Model):
image = models.ImageField(upload_to="upload/", blank=True, null=True)
thumbnail = models.ImageField(upload_to='upload/thumbs/', blank=True,