Added sites framework

This commit is contained in:
David Gelvin 2010-09-30 12:43:26 +03:00
parent 9cf3b5b9f1
commit 5ccc3f012a
3 changed files with 11 additions and 2 deletions

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with EAV-Django. If not, see <http://gnu.org/licenses/>.
VERSION = (0, 9, 1)
VERSION = (0, 9, 2)
def get_version():
version = "%s.%s" % (VERSION[0], VERSION[1])

View file

@ -40,6 +40,8 @@ from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager
from django.conf import settings
from .validators import *
@ -150,6 +152,7 @@ class Attribute(models.Model):
class Meta:
ordering = ['name']
unique_together = ('site', 'slug')
TYPE_TEXT = 'text'
TYPE_FLOAT = 'float'
@ -172,6 +175,9 @@ class Attribute(models.Model):
name = models.CharField(_(u"name"), max_length=100,
help_text=_(u"User-friendly attribute name"))
site = models.ForeignKey(Site, verbose_name=_(u"site"),
default=Site.objects.get_current)
slug = EavSlugField(_(u"slug"), max_length=50, db_index=True,
help_text=_(u"Short unique attribute label"),
primary_key=True)
@ -199,6 +205,9 @@ class Attribute(models.Model):
required = models.BooleanField(_(u"required"), default=False)
on_site = CurrentSiteManager()
objects = models.Manager()
def get_validators(self):
'''
Returns the appropriate validator function from :mod:`~eav.validators`

View file

@ -53,7 +53,7 @@ class EavConfig(object):
By default, all :class:`~eav.models.Attribute` object apply to an
entity, unless you provide a custom EavConfig class overriding this.
'''
return Attribute.objects.all()
return Attribute.on_site.all()
class Registry(object):