What’s the best way to store a phone number in Django models?

I am storing a phone number in model like this: phone_number = models.CharField(max_length=12) The user would enter a phone number and I would use the phone number for SMS authentication. This application would be used globally. So I would also need a country code. Is CharField a good way to store a phone number? And, … Read more

How to convert a Django QuerySet to a list?

I have the following: answers = Answer.objects.filter(id__in=[answer.id for answer in answer_set.answers.all()]) then later: for i in range(len(answers)): # iterate through all existing QuestionAnswer objects for existing_question_answer in existing_question_answers: # if an answer is already associated, remove it from the # list of answers to save if answers[i].id == existing_question_answer.answer.id: answers.remove(answers[i]) # doesn’t work existing_question_answers.remove(existing_question_answer) I … Read more

How to get Request.User in Django-Rest-Framework serializer?

I’ve tried something like this, it does not work. class PostSerializer(serializers.ModelSerializer): class Meta: model = Post def save(self): user = self.context[‘request.user’] title = self.validated_data[‘title’] article = self.validated_data[‘article’] I need a way of being able to access request.user from my Serializer class. 13 Answers 13