Friday, September 23, 2022

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

Add an attribute to instance? 

On Fri, 23 Sep 2022, 19:21 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/CAHAc2jcbEjKR%2Bpkww3r8sB3Kh1%3D3JfhYQA9niMBHhiZ9AUgE8w%40mail.gmail.com.

No comments:

Post a Comment