Hey, Always send properly formatted code.
class StreamPlatfrom(models.Model): name = models.CharField(max_length=100) about = models.CharField(max_length=150, null=True) website = models.URLField() id = models.UUIDField( primary_key=True, default=uuid.uuid4, editable=False, unique=True ) createdAt = models.DateTimeField(auto_now_add=True) def __str__(self) -> str: return self.name class WatchList(models.Model): title = models.CharField(max_length=150) storyline = models.TextField() active = models.BooleanField() releaseDate = models.DateField() releaseYear = models.IntegerField() stream = models.ManyToManyField(StreamPlatfrom) id = models.UUIDField( primary_key=True, default=uuid.uuid4, editable=False, unique=True ) createdAt = models.DateTimeField(auto_now_add=True) def __str__(self) -> str: return self.title # WatchListSerializer class WatchListSerializer(serializers.ModelSerializer): reviews = ReviewSerializer(many=True, read_only=True) class Meta: model = WatchList fields = "__all__" depth = 1 def create(self, validated_data): stream_data = validated_data.pop("stream", []) print("Stream_data", stream_data) watchlist = WatchList.objects.create(**validated_data) for stream in stream_data: stream_obj = StreamPlatfrom.objects.get(name=stream["name"]) watchlist.stream.add(stream_obj) return watchlist # StreamPlatformSerializer class StreamPlatformSerializer(serializers.ModelSerializer): class Meta: model = StreamPlatfrom fields = "__all__" I dont see ReviewSerializer anywhere in the code. I dont see a serializer for stream objects either. Answer to your question lies in the below page. https://www.django-rest-framework.org/api-guide/serializers/#serializers Thanks! Regards, Chetan Ganji +91-900-483-4183 ganji.che...@gmail.com http://ryucoder.in On Mon, Jul 24, 2023 at 11:14 PM Pratap Padekar <unitedprat...@gmail.com> wrote: > > 1. here are my models: > 2. [10:23 PM] > class StreamPlatfrom(models.Model): name = > models.CharField(max_length=100) about = models.CharField(max_length=150, > null=True) website = models.URLField() id = > models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, > unique=True) createdAt = models.DateTimeField(auto_now_add=True) def > __str__(self) -> str: return self.name class WatchList(models.Model): > title = models.CharField(max_length=150) storyline = models.TextField() > active = models.BooleanField() releaseDate = models.DateField() releaseYear > = models.IntegerField() stream = models.ManyToManyField(StreamPlatfrom) id > = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, > unique=True) createdAt = models.DateTimeField(auto_now_add=True) def > __str__(self) -> str: return self.title > > > 1. > 1. and here are my serializer: > 2. [10:23 PM] > # WatchListSerializer class > WatchListSerializer(serializers.ModelSerializer): reviews = > ReviewSerializer(many=True, read_only=True) class Meta: model = > WatchList > fields = ("__all__") depth = 1 def create(self, validated_data): > stream_data = validated_data.pop('stream', []) print("Stream_data", > stream_data) watchlist = WatchList.objects.create(**validated_data) for > stream in stream_data: stream_obj = > StreamPlatfrom.objects.get(name=stream['name']) > watchlist.stream.add(stream_obj) return watchlist # > StreamPlatformSerializer class > StreamPlatformSerializer(serializers.ModelSerializer): class Meta: > model= > StreamPlatfrom fields = ("__all__") > 3. [10:23 PM] > For some reason the create method is not working > 4. [10:24 PM] > When I add stream it returns an empty array > 2. > When I add stream it returns an empty array > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-rest-framework+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/67e18478-75d0-4ebc-aa81-78b2552bd153n%40googlegroups.com > <https://groups.google.com/d/msgid/django-rest-framework/67e18478-75d0-4ebc-aa81-78b2552bd153n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAMKMUjtWeyr%2BQ8KTf0cXOxYDpCDHo5gtgYQzD_vF4y%3DsBCfx5w%40mail.gmail.com.