1,913 questions
2
votes
1
answer
34
views
Where to put the validation in fields in api django rest framework? Models or Serializations?
I am studying the Django REST framework and building an API, but I have a simple question: Where should I add my validation fields? What’s the best place to do that—models or serializers? I know that ...
0
votes
0
answers
51
views
getting the choice names from an array of values in Django Rest Framework
I am trying to get the choice labels from a field that stores an array of choices - I am able to get the label when the field has a single value.
Here is the model:
class TobaccoUse(models.Model):
...
-1
votes
1
answer
68
views
Django serializer to convert list of dictionary keys to model fields
I am using pandas openpyxl to read excel file in my project. After reading the excel file I end up with list of dictionaries. These dictionaries have keys such as "Year 2024", "Range&...
0
votes
1
answer
45
views
Different name of serializer data django
I want to serializer a list of dicts that contain a whitespace.
Obviously I can't write cat name = serializer.Charfield(...) in Python
(see the space between the and cat).
So, I tried source=, but I ...
0
votes
2
answers
58
views
Django serializer returning empty array
I have minimal experience with Python, and no experience with Django, but I have been tasked with fixing a bug in a Django app.
I have the following models
class SurveyResponse(models.Model):
...
0
votes
1
answer
55
views
Django REST API view post serializer.save sets one parameter 'null'
In Django, I have the following model:
class business(models.Model):
business_category = models.ForeignKey(businessCategory, related_name='businesss', on_delete=models.CASCADE)
partner1 = ...
0
votes
2
answers
61
views
Issues with Django Rest Framework Serializer for Nested Data Handling
I’m working on a Django project using Django Rest Framework (DRF), and I’m facing issues with serializing and deserializing nested data for my Child model. Here’s a summary of my setup and the problem:...
4
votes
0
answers
89
views
Djoser Create User keeps returning field required and is not creating users
I ran into a problem in postman that was not there until yesterday when I was working with it and it was working fine, but now it is not working anymore.
I'm trying to create a user using djoser ...
0
votes
1
answer
39
views
Nested Serializers create method for each serializer
I have a Club Model as well as an Address model.
class Club(models.Model):
name = models.CharField(max_length=100)
owner = models.ForeignKey(UserAccount,on_delete=models.CASCADE,related_name = ...
-3
votes
1
answer
80
views
Validating POST parameters with serializers in Django [closed]
I'm trying to implement a simple validator for my POST parameters
My input looks like this:
{
"gage_id": "01010000",
"forcing_source":"my_source",
"...
0
votes
1
answer
40
views
How to Resolve Null Field Errors in Django When Creating a Task with Subtasks and Users
I'm encountering issues when trying to create a task with subtasks and users in my Django application. The task creation fails due to validation errors, specifically with the subtasks and users fields....
1
vote
1
answer
87
views
Integrity Error - UNIQUE constraint failed. How do i deal with it? Django
I am new to the DRF framework, and am building a small project. I want to create a User instance (the built-in one) and while doing so also make a Seller instance linked to it during a user signup.
...
0
votes
1
answer
52
views
Is there a better way to update all relation rows with `ForegnKey` relation in `Django ORM`
I have two models, one like this:
class PhysicalSensor(models.Model):
name = models.CharField(unique=True, max_length=255)
def __str__(self) -> str:
return self.name
class Sensor(...
0
votes
1
answer
33
views
How to get attribute of a foreign key inside serializer in Django REST framework?
I have two models named Market, Exchange
class Exchange(models.Model):
name = models.CharField(max_length=20)
class Market(models.Model):
exchange = models.ForeignKey(Exchange, on_delete=...
2
votes
1
answer
41
views
Why dropdown field is disappeared in Django Rest Framework when using custom serializer for a field?
I am trying to use Django, DRF, ViewSet and Serializers to build a simple weblog.
I have a main app and inside it:
main\models.py:
from django.db import models
from django.contrib.auth.models import ...
1
vote
1
answer
70
views
Unable to create UserProfile object for User
I have a User model and a UserProfile model with a one-to-one relationship. I'm using a serializer to create users, and I want to automatically create a corresponding UserProfile object for each user ...
2
votes
2
answers
46
views
Get absolute image's path in DRF
I'm recently approaching drf and I want to create a system that returns a user's information. Among the various fields, the user has an avatar which should return the URL of the photo where it is ...
0
votes
0
answers
66
views
axios response.data is empty when django returns a queryset with a single element
I am using axios to get some data from my backend API made with django.
Something very very wired is happening and I have been debugging this for hours.
This is the axios function that gets the data:
...
0
votes
2
answers
110
views
DRF: Serialize field with different serializers and many=True
I have the following models in my django rest framework app:
class Question(models.Model):
class Type(models.TextChoices):
TEXT = 'text', 'text question'
RADIO = 'radio', 'choosing ...
0
votes
0
answers
38
views
Parsing nested JSON in Django Rest Framework
I am trying to serialize a geometry dict which also contains a location dict and map that dictionaries values to my model. The data comes in two levels deep and is mapped to a single model, because ...
1
vote
0
answers
50
views
Parent-child relationship modeling REST API
I have a sample table below with a parent-child relationship.
id
parent
1
null
2
1
3
2
4
null
I have to represent this in the UI as a tree structure. What is or are the best approaches to this? Do I ...
0
votes
1
answer
66
views
Can't validate form with a many=true field in Django-rest
I am trying to use Django-rest as an api for a front end in astro, the think is I am finding a problem when doing my post:
{'items': [ErrorDetail(string='This field is required.', code='required')]}
...
0
votes
1
answer
160
views
In Django, where does the "data" field come from in the Serializer class?
I see in a bunch of django code, especially in viewsets, that when serializer is initialized like the following:
class UserViewSet(viewsets.ModelViewSet):
"""
A viewset that ...
0
votes
1
answer
56
views
How to remove instances inside serializer
Here inside the serializer using to_representation, validate to remove the instance that doesn't satisfy the condition "completed == total_videos" but gets all the instances, so please ...
0
votes
0
answers
117
views
Serializing multiple inheritance models in Django REST Framework
I have this model structure:
class Main (models.Model):
name=models.Charfield(max_length=50)
...
class Category (Main):
type=models.Charfield(max_length=50)
...
class SubCategory1(...