Пример #1
0
 def save(self, *args, **kwargs):
     self.code = code_generate(self.name)
     object_id = self.id
     super(AnimalBreed, self).save(*args, **kwargs)
     auditor = None
     if object_id is not None:
         auditor = Auditor(content_object=self,
                           tag=str(self),
                           action='update')
     else:
         auditor = Auditor(content_object=self,
                           tag=str(self),
                           action='save')
     auditor.save()
Пример #2
0
    def clean(self):
        instance = super(AnimalBreedForm, self).save(commit=False)
        instance.name = self.cleaned_data.get('name')
        instance.animal_type = self.cleaned_data.get('animal_type')
        instance.code = code_generate(instance.name)

        min_size = 3
        if len(instance.name) < min_size:
            raise forms.ValidationError(
                "El nombre debe contener mas de {} caracteres".format(
                    str(min_size-1)))
        else:
            try:
                instance.save()
            except IntegrityError as e:
                raise ValidationError(str(e))
Пример #3
0
    def clean_name(self):
        clean_dict = self.cleaned_data
        name = clean_dict.get('name')

        try:
            listing = AnimalType.objects.get(code=code_generate(name))
        except Exception as e:
            listing = None

        if listing is not None:
            raise forms.ValidationError(
                "Ya existe Tipo Animal con nombre {}.".format(name))

        if len(name) < 3:
            raise forms.ValidationError(
                "El nombre debe contener mas de tres caracteres")
        return name
Пример #4
0
 def __str__(self):
     return code_generate(self.name)