简体   繁体   中英

Difference between Compress and Clean method in Django Form Fields

I'm writing a custom date field for Credit Card Expiration Fields. I've noticed that in custom field examples, there are two major part that we need to override, clean and compress methods.

I know that we can validate and change return values of the field value in clean method. But what about compress method? Why do we need that and what's the difference in between of clean and compress method?

compress only exists for subclasses of MultiValueField . As the documentation there explains, you use it in place of clean to convert the multiple values (one for each field) into a single value.

For every other type of field, you use clean .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM