Passing kwargs into get_or_create method in Django -




i have model custom save function, want perform functions based on condition this:

class classname(models.model):      def save(self, *args, **kwargs):         reindex =  **kwargs.pop("reindex")          super().save(*args, **kwargs)          if reindex:             people.objects.create() 

now inside task want call following:

kwargs = { "reindex": false} classname.objects.get_or_create(**kwargs) 

when create, runs save function, it's giving me error saying reindex not field. have been researching while , can't figure out do. maybe can point me in right direction.

i want pass in argument get_or_create, can conditionally perform function in save method.

thank in advance!

when do

kwargs = { "reindex": false} classname.objects.get_or_create(**kwargs) 

it equivalent

classname.objects.get_or_create(reindex=false) 

thus, since reindex appears not field defined in model classname, error.


btw, beyond things appear erroneous, e.g. reindex = **kwargs.pop("reindex"), should define reindex 1 of fields of model. admit answer blindly, because me, class definition cannot work so. if 1 assumes reindex integer field, do

class classname(models.model):     reindex = models.integerfield(null=true)      def save(self, *args, **kwargs):         super(classname, self).save(*args, **kwargs)         if "reindex" in kwargs:             people.objects.create() 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -