python - Django: Model field for storing a list of floats? -
I want to store a variable-length list of floats in Django. Com-separated Integer field, but is there anything I can use? Would it be best if I applied my commonsparent floatford or is there something that is missing me completely? Thank you.
I think you can easily define your own area:
comma_separated_float_list_re = re.compile ('^ [[+ +] \ d * \ \ d + [, \ s] *) + $') validate_comma_separated_float_list = RegexValidator (comma_separated_float_list_re, _ (u ' Class CommaSeparatedFloatField (CharField): default_validators = [validators.validate_comma_separated_float_list] Description = _ ("floats apart from comma") def formfield (self, ** kwargs): defaults = {'Error_messages': {'invalid': _ (.u'Enter only by commas Different floats'),}} defaults.update (kwargs) return super (CommaSeparatedFloatField, self) .formfield (** defaults)
This snippet is not, but you may find it Can adapt for your needs.
Comments
Post a Comment