Trying:
ModelA.objects.filter(pk=id_of_a_instance).update(b_id=id_of_b_instance)
which yields 'FieldNameDoesNotExist' because 'get_field_by_name' only has
'b' as a field name for ModelA, not b_id (which is strange given that is
what is actually stored).
Then I try:
ModelA.objects.filter(pk=id_of_a_instance).update(b=id_of_b_instance),
which says it needs an instance of ModelB, not a number.
Which means I will be stuck with an extra query:
model_b_list = list(ModelB.objects.filter(id_in=[list of ids for a
instances])
and then have to iterate through the ModelA instances and assign the
actual ModelB instances
--
Ticket URL: <https://code.djangoproject.com/ticket/21144>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
My mistake--this should not have been submitted, was still debugging and
this is not an issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:1>
Comment (by mbhagya@…):
Sorry but what happened to this bug? Is this fixed in a later version?
Because I can still see this in 1.5.
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:2>
Comment (by Microserf):
Could I ask for additional clarifications regarding why this issue was
closed and set to invalid? This seems like a legitimate use case to
support, no?
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:3>
* status: closed => new
* resolution: invalid =>
* stage: Unreviewed => Accepted
Comment:
Looks like the original reporter closed it without much explanation. I'm
reopening, because I agree this is a valid case and should be supported
somehow (I think probably by accepting raw IDs for an FK field in
`update`).
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:4>
* owner: nobody => vaskalas
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
Issue was fixed in commit c21e86ab9e3e5ebd6d245d038cb0cb352cd84c3a. Added
unit tests to verify fix in https://github.com/django/django/pull/4499
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:6>
Comment (by vaskalas):
The unit test was added actually added in this commit,
https://github.com/django/django/commit/e01b5a5823fa06a63382f87472978a16c77048d2
--
Ticket URL: <https://code.djangoproject.com/ticket/21144#comment:7>