Tuesday, January 23, 2018

Re: unbound method save() must be called with MyModel instance as first argument

Also it looks like in your separate tread Daniel wrote:

> model_instance = model()

That is how you can create instance from model.

Regards,
C

On Jan 23, 2018, at 9:29 PM, Costja Covtushenko <kostyak7676@gmail.com> wrote:

Hi,

I did not mention your use of `stattr()`.
I was about class VS instance of that class.

Did you say that problem is with unbound method `save()` which should be called with instance as a first argument?

Regards,
C

On Jan 23, 2018, at 9:18 PM, Tom Tanner <dontsendemailhereok@gmail.com> wrote:

In my case, I'm using `setattr()` because I need to access a field via string and set it. I can't do `obj.myCol = "blah blah"` because this whole code is part of a `manage.py` command I'm setting up that asks the user to input the name of the model and column they want to add a new record for.

On Tuesday, January 23, 2018 at 7:59:11 PM UTC-5, Costja Covtushenko wrote:
Hi,

It looks like with get_model() you've gotten Model class not Model instance.
You can use `save()` on instance only.
You need to have something like:

class_ = get_model(…)
instance = class_()
instance.save()

I hope that make sense to you.

Regards,
C.

On Jan 23, 2018, at 7:43 PM, Tom Tanner <dontsende...@gmail.com> wrote:

get_model


-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f06c409b-ca0a-4350-8736-26ad0553ab67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


No comments:

Post a Comment