Thanks Chris
It turned out I hadn't read the docs properly. Prior to posting the
problem I had tried ...
instance.item_pictogram_set.remove(pic)
... to be told the relatedmanager object didn't have a remove attribute
when (I thought) it should. So I adjusted the database to make both fk
fields nullable and deliberately made them None to get the code working.
But I should have stuck with nullable foreign keys and the above
instance.item_pictogram_set.remove(pic) because that was all that is
required.
I hadn't read beyond the example code in the docs [1] for the remove
method where it says ...
"In order to prevent database inconsistency, this method only exists on
ForeignKey objects where null=True. If the related field can't be set to
None (NULL), then an object can't be removed from a relation without
being added to another. In the above example, removing e from
b.entry_set() is equivalent to doing e.blog = None, and because the blog
ForeignKey doesn't have null=True, this is invalid."
[1]
https://docs.djangoproject.com/en/dev/ref/models/relations/#django.db.models.fields.related.RelatedManager.remove
Mike
On 13/12/2012 11:30pm, Chris Cogdon wrote:
I'm going to take a guess that when you "drop one" of them, deleting it,
there's still a query going on that might want to refer to the other
one, and the to_python fails because that reference doesn't exist anymore.
You might have better luck if you're using a OneToOne or ForeignKey
(onetomany), which will let django manage that relationship for you.
On Wednesday, December 12, 2012 4:21:59 PM UTC-8, Mike Dewhirst wrote:
I'm getting an unexpected validation error in Admin which baffles me.
Any hints appreciated ... here is the traceback
http://dpaste.com/844972/
At the bottom of the traceback where the error is raised, the local
vars
are ...
self <django.forms.models.ModelChoiceField object at
0x02414890>
value u'33'
key 'pk'
When I save the item, it auto-generates many-to-many connections to a
few standard images in the database via a through table. However there
is a rule which says "if ever these two images are connected to an
item,
only keep this one and drop that one."
I use a post-save signal to "drop that one" using ...
Item_Pictogram.objects.filter(item=instance, pictogram=pic,
via='auto').delete()
The local var value above being u'33' happens to be the exact pk of the
Item_Pictogram record I want to delete - I checked in Postgres.
The pk should be an integer but I suppose that's nothing.
Thanks for any help
Mike
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/TjN8sz1YkQwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.