Friday, September 23, 2022

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

Hello Sencer,
You could override the serializer class' create method.


Hope this helps you mate.

Cheers,
Tega Ukavwe
Python Like English

On Fri, Sep 23, 2022 at 7:21 PM Sencer Hamarat <sencerhamarat@gmail.com> wrote:
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.


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZjF3_eQ6KSQKnatVHQGQsh%3Dz6Kr4pdVEM151VbnSq5N1g%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BbC3qVJw0x5KZtToCrvai5n6acjOFaAch%2BQGzrkSyxn3Fp9-A%40mail.gmail.com.

No comments:

Post a Comment