How to simplify phone_number field update Process in django including verification

Problem Description:

We have a User model where Phone number is been set as username and its unique=True, We also have a field where to represent verified/unverified users. And we verify users by OTP verification to phone number. So now we need to add a new feature where user can replace his phone_number and then he will go to verification process and then we will change his number.

And also We need to preserve his previous number (which he already verified) until this new number is verified. If for some reason user decides to go back without verification we delete newly added number and keeps his old number as username.

So what would be the best way to approach this problem

What I'm considering to have another Model linked with ForeignKey to User

class AlternativeNumber(models.Model):
    user = User() # forignkey
    number = Charfield
    is_verfied = BooleanField

So we will be verifying users number and replacing his original number from his alternativenumber_set

Do you think we can simply it more. Do you think it might have some flaws or we go with a better appraoch ? thanks.

In my opinion you can add two new fields to the User class

alternative_number = CharField
is_aletrnative_verfied = BooleanField

which is really similar to your approach, but it is simpler because all the data is in one table. if a user did not verify his number then you can create a cron job that checks if the is_aletrnative_verfied and if it was false then delete whatever value is in the alternative_number just for the data to be consistent.

Hope you find this helpful!

Back to Top