Is there a way to pass arbitrary argument from serializer.save to model.save method

40 views
Skip to first unread message

Sencer Hamarat

unread,
Sep 23, 2022, 2:22:07 PM9/23/22
to django...@googlegroups.com
Hi,

I need to pass an arbitrary argument from the serializer.save() method to model.save() method?

Such as:

serialized_data = AModelSerializer(instance, data=adata_dict)
if serialized_data.is_valid():
    serialized_data.save(an_arg="value")

class Amodel(models.Model)
    def save(*args, **kwargs):
         extra_arg = kwargs["an_arg"]


The method demonstrated above is not working due to nature of serializer. Bu I can't figure out any other way to do that.

Right now, I'm open to suggestions.


Shaheed Haque

unread,
Sep 24, 2022, 2:17:13 AM9/24/22
to django...@googlegroups.com
Add an attribute to instance? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZjF3_eQ6KSQKnatVHQGQsh%3Dz6Kr4pdVEM151VbnSq5N1g%40mail.gmail.com.

Tega Ukavwe

unread,
Sep 24, 2022, 9:35:39 AM9/24/22
to django...@googlegroups.com
Hello Sencer,
You could override the serializer class' create method.


Hope this helps you mate.

Cheers,
Tega Ukavwe
Python Like English

Reply all
Reply to author
Forward
0 new messages