Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented API #357

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Implemented API #357

wants to merge 3 commits into from

Conversation

ORENYT
Copy link

@ORENYT ORENYT commented Oct 11, 2023

Created api for all models with different serializers

@@ -5,6 +5,23 @@ class Movie(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
duration = models.IntegerField()
actors = models.ManyToManyField("Actor")
genres = models.ManyToManyField("Genre")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add related name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for what reason? They are not used

@@ -1,24 +1,27 @@
from rest_framework import serializers

from cinema.models import Movie
from cinema.models import Movie, Actor, Genre, CinemaHall
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use relative imports, IMHO it is better

Copy link
Author

@ORENYT ORENYT Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative imports are a very bad practice)

Comment on lines +49 to 52
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify it with raise_exceptions = True https://stackoverflow.com/a/40373171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants