Category : django-rest-framework

Hello guys I am new in Django REST API. I want your help. I am trying to join my two models : User and blogs to get specific api output like this: { "blog_id": 1, "title": "first blog", "description": "hola", "image": "/images/phone.jpg", "create_at": "2021-04-08T14:24:51.122272Z", "update_at": "2021-04-08T14:37:00.287746Z", "user": 1, "user_name": "superuser", "first_name": "Dannis", "email": "[email protected]" } ..

Read more

Below is my view, url and model. I have stored some values in my database, and I make patientNRIC as the primary key, now I wanted to access the respective patient details through their patientNRIC, however, I could not do that, it always show me the error of mismatch. plss helllpp meeeee. Thanks #view.py from ..

Read more

I have been asked to perform a simple task where I can do the following User can register and login as a doctor or patient Doctor has many clinics. clinic include (name, price, date, start_time, end_time) Patients can reserve doctor clinics Display doctors and patients reservations Use Python, django, django rest framework and relational database ..

Read more

[I’m asking about DRF but this question is more about a general approach to a situation like mine] Let’s say on my backend I have a Category and a Question model like these: class Category(models.Model): name = models.TextField() class Question(models.Model): text = models.TextField() category = models.ForeignKey( Category, on_delete=models.SET_NULL, null=True, related_name="questions" ) I have a vue ..

Read more

This is the sample view where I am taking some query_params and I want to access the same in serializer which will I use in this view accordingly. class SomeApi(APIView): def get(self, request): username = request.query_params.get(‘username’) page = request.query_params.get(‘page’) phone = request.query_params.get(‘phone’) if username and page and phone: return Response({‘message’:’some message’}, status=status.HTTP_200_OK) return Response({‘message’:’error’}, status=status.HTTP_400_BAD_REQUEST) ..

Read more

i am developing web app related to election and try to implement authorize token concept using rest_framework_simplejwt.serializers and while running this code i encounter error related to str class like this: AttributeError: ‘str’ object has no attribute ‘decode’ from this part of code: data[‘refresh’] = str(refresh) class AuthTokenObtainSerializer(TokenObtainPairSerializer): """ Seializer for th user authentication object. ..

Read more

I have a generics.RetrieveUpdateAPIView which accepts and excel file and stores it / updates it on an S3 bucket. My main model is class Product(models.Model): …. results_file = models.FileField(upload_to=get_results_filename, max_length=254) …. My question is which is the cleanest way to mock an excel file for testing purposes. I am trying to implement a test method ..

Read more

I want change required message to my custom message. My model -> class TeacherProfile(models.Model): address = models.CharField(max_length=100) subject = models.CharField(max_length=100) price = models.IntegerField() bio = models.TextField() tel_number = models.CharField(max_length=25,validators=[number_regex]) teacher = models.OneToOneField(User, on_delete=models.CASCADE) def __str__(self): return str(self.teacher) When I empty the empty form, it gives an default error "This field may not be blank.". i ..

Read more