You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Ambulance(models.Model):
ambulance_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
ambulance_name = models.CharField(max_length=255)
forms = models.ManyToManyField(Form)
class Form(models.Model):
form_id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
form_title = models.CharField(max_length=255)
class Page(models.Model):
page_id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
page_title = models.CharField(max_length=100, default='Untitled Page')
form = models.ForeignKey(
Form,
related_name='pages',
on_delete=models.CASCADE,
null=True
)
And the serializers as follow:
class AmbulanceSerializer(serializers.ModelSerializer):
forms = FormSerializer(read_only=True, many=True)
class Meta:
model = Ambulance
fields = ['ambulance_id', 'ambulance_name', 'forms']
class FormSerializer(ModelSerializer):
pages = PageSerializer(many=True, read_only=True)
class Meta:
model = Form
fields = ['form_id', 'form_title', 'pages']
class PageSerializer(ModelSerializer):
class Meta:
model = Page
fields = '__all__'
They were working and give me the nested object that I wanted but after adding many-to-many relationships, it gives me an internal server error 500 and it didn't tell me what the problem was, after debugging I found the problem occurs when calling AmbulanceSerializer(ambulance) or FormSerializer(form)
Could someone give me some hint? and what the problem actually!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have three models like those:
And the serializers as follow:
They were working and give me the nested object that I wanted but after adding many-to-many relationships, it gives me an internal server error 500 and it didn't tell me what the problem was, after debugging I found the problem occurs when calling
AmbulanceSerializer(ambulance)
orFormSerializer(form)
Could someone give me some hint? and what the problem actually!
Beta Was this translation helpful? Give feedback.
All reactions