예제 #1
0
    def save(self, *args, **kwargs):
        """
        Saves the Attribute and auto-generates a slug field
        if one wasn't provided.
        """
        if not self.slug:
            self.slug = EavSlugField.create_slug_from_name(self.name)

        self.full_clean()
        super(Attribute, self).save(*args, **kwargs)
예제 #2
0
    def derive_datatype(self):
        """
        We map our field_type to the appropriate data_type here.
        """
        # set our slug based on our command and keyword
        self.slug = "%s_%s" % (self.xform.get_primary_keyword(), EavSlugField.create_slug_from_name(self.command))
        typedef = self.lookup_type(self.field_type)

        if not typedef:
            raise ValidationError("Field '%s' has an unknown data type: %s" % (self.command, self.datatype))

        self.datatype = typedef['db_type']
예제 #3
0
    def derive_datatype(self):
        """
        We map our field_type to the appropriate data_type here.
        """
        # set our slug based on our command and keyword
        self.slug = "%s_%s" % (self.xform.get_primary_keyword(), EavSlugField.create_slug_from_name(self.command))
        typedef = self.lookup_type(self.field_type)

        if not typedef:
            raise ValidationError("Field '%s' has an unknown data type: %s" % (self.command, self.datatype))

        self.datatype = typedef['db_type']
예제 #4
0
파일: models.py 프로젝트: hovel/django-eav
    def save(self, *args, **kwargs):
        '''
        Saves the Attribute and auto-generates a slug field if one wasn't
        provided.

        If parent provided is not already a ContentType, calculate this.
        Yes, this means you can't add Attributes for the ContentType model.
        '''
        if not getattr(self, 'slug', None):
            self.slug = EavSlugField.create_slug_from_name(self.name)
        if not getattr(self, 'site', None):
            self.site = Site.objects.get_current()
        self.full_clean()
        super(Attribute, self).save(*args, **kwargs)
예제 #5
0
    def derive_datatype(self):
        """
        We map our field_type to the appropriate data_type here.
        """
        # set our slug based on our command and keyword
        self.slug = "%s_%s" % (self.xform.keyword, EavSlugField.create_slug_from_name(self.command))

        for (field_type, name, datatype, func, xforms_type) in XFormField.TYPE_CHOICES:
            if field_type == self.field_type:
                self.datatype = datatype
                break

        if not self.datatype:
            raise ValidationError("Field '%s' has an unknown data type: %s" % (self.command, self.datatype))