extract validators and decorator to utils
[qcg-portal.git] / filex / models.py
index 71a8362..82e73b4 100644 (file)
@@ -1,3 +1,22 @@
+# coding=utf-8
+from django.conf import settings
 from django.db import models
 
-# Create your models here.
+from filex.utils import host_validator, path_validator
+
+
+class Favorite(models.Model):
+    owner = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"Właściciel", related_name='favorites')
+    host = models.CharField(u"Host", max_length=256, validators=[host_validator])
+    path = models.CharField(u"Ścieżka", max_length=1024, default='~', validators=[path_validator])
+
+    created = models.DateTimeField(u"Utworzono", auto_now_add=True)
+    updated = models.DateTimeField(u"Uaktualniono", auto_now=True)
+
+    class Meta:
+        verbose_name = u"Ulubiona lokalizacja"
+        verbose_name_plural = u"Ulubione lokalizacje"
+        unique_together = ('owner', 'host', 'path')
+
+    def __unicode__(self):
+        return u'{}/{} ({})'.format(self.host, self.path, self.owner)