1👍
✅
I would do that in the model’s save:
import re
class Team(models.Model):
team_member_phone = models.CharField(max_length=128, default='',)
team_member_phone_clean = models.CharField(max_length=128, default='',)
def set_member_phone_clean(self):
self.team_member_phone_clean = re.sub(r"(\s)|([^\d])", "", self.team_member_phone)
def save(self, *args, **kwargs):
self.set_member_phone_clean()
super(Team, self).save(*args, **kwargs)
👤nima
0👍
yes you have to define it in your form TeamAddForm and it will automatically be called when you check form.is_valid() provided you have override the form’s clean method
def clean(self):
cleaned_data = super(TeamAddForm, self).clean()
# do your processing here with self.fields['team_member_phone'] and return back the data
return cleaned_data
- Django objects.filter with args in loop
- ◈ LoginRequired for the view 💈 Django 1.8
- Django – Limiting the amount of objects created to 3 and being able to update them.
- How to check the raw sql statement of getting the foreign key set of a model instance?
- Python unicode #-*- coding: utf-8 -*- not doing the job…where to encode?I think I need to remove str and encode
Source:stackexchange.com