[Fixed]-How to generate a dynamic model record based on another record

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

Leave a comment