From f522655a6c1bbabaabb361a408aad7bb71517dde Mon Sep 17 00:00:00 2001 From: David Gelvin Date: Tue, 7 Sep 2010 12:34:03 +0000 Subject: [PATCH 1/2] Added stuff --- fields.py | 4 +++- models.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fields.py b/fields.py index a4ea2d5..5175217 100644 --- a/fields.py +++ b/fields.py @@ -2,7 +2,7 @@ import uuid import re from django.db import models -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy as _ from django.core.exceptions import ValidationError class EavSlugField(models.SlugField): @@ -27,3 +27,5 @@ class EavSlugField(models.SlugField): # Remove non alphanumeric characters name = re.sub('[^\w]', '', name) + + diff --git a/models.py b/models.py index 93d16e1..38cd5b5 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,5 @@ import re +from datetime import datetime from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -60,6 +61,10 @@ class EavAttribute(models.Model): datatype = models.CharField(_(u"data type"), max_length=6, choices=DATATYPE_CHOICES) + created = models.DateTimeField(default=datetime.now) + + modified = models.DateTimeField(auto_now=True) + labels = models.ManyToManyField(EavAttributeLabel, verbose_name=_(u"labels")) From 9b2402af7a5b0b2415cde654a507a7cf1d0714b2 Mon Sep 17 00:00:00 2001 From: David Gelvin Date: Tue, 7 Sep 2010 12:44:13 +0000 Subject: [PATCH 2/2] Fixed auto slug --- fields.py | 4 ++-- models.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fields.py b/fields.py index 5175217..95d3890 100644 --- a/fields.py +++ b/fields.py @@ -26,6 +26,6 @@ class EavSlugField(models.SlugField): name = re.sub('\s+', '_', name) # Remove non alphanumeric characters - name = re.sub('[^\w]', '', name) - + return re.sub('[^\w]', '', name) + diff --git a/models.py b/models.py index 38cd5b5..d6befb8 100644 --- a/models.py +++ b/models.py @@ -22,7 +22,7 @@ class EavAttribute(models.Model): The A model in E-A-V. This holds the 'concepts' along with the data type something like: - >>> EavAttribute.objects.create(name='Height', datatype='float', slug='height') + >>> EavAttribute.objects.create(name='Height', datatype='float') >>> EavAttribute.objects.create(name='Color', datatype='text', slug='color') @@ -61,9 +61,9 @@ class EavAttribute(models.Model): datatype = models.CharField(_(u"data type"), max_length=6, choices=DATATYPE_CHOICES) - created = models.DateTimeField(default=datetime.now) + created = models.DateTimeField(_(u"created"), default=datetime.now) - modified = models.DateTimeField(auto_now=True) + modified = models.DateTimeField(_(u"modified"), auto_now=True) labels = models.ManyToManyField(EavAttributeLabel, verbose_name=_(u"labels")) @@ -139,6 +139,13 @@ class EavValue(models.Model): attribute = models.ForeignKey(EavAttribute) + def save(self, *args, **kwargs): + self.full_clean() + super(EavValue, self).save(*args, **kwargs) + + def clean(self): + pass + def _blank(self): self.value_text = self.value_float = self.value_int = self.value_date = None