I was wondering what would be the best approach . I've been agonizing on what is the best way to accomplish a given task. It is a project with a react frontend and django rest framework backend. I am working on the backend with the django rest framework .
Task:
- To query a user by their phonenumber which is stored as the username field.
- To add a user to a profile model and add an extra field which is required by the profile model
- To create the new profile with the user as the profiles user .
e.g
Profile Model:
User - ForeignKey
ExtraField - Charfield
My question is which of these solutions is better .
- Should I build a url like this : domain/users/{phonenumber} and post the Extra field and query the user like this.
def get_object(self):
return get_object_or_404(User,username=self.kwargs['phonenumber'])
user= get_object()
or
- Should I post both the phonenumber and the extrafield and query the user from the backend like this.
user = get_object_or_404(User,username=request.data.get('phonenumber'))
both work but which would be the best practice if it even matters at all.