I'm getting a baffling ValidationError.
Request URL: http://127.0.0.1:8000/admin/assembly/item/4/
Django Version: 1.4.3
Exception Type: ValidationError
Exception Value: [u'Select a valid choice. That choice is not one of
the available choices.']
Exception Location: C:\usr\bin\lib\site-packages\django\forms\models.py
in to_python, line 988
Python Version: 2.7.3
Background ...
I have an Item model which has two one-to-many relationships with other
types of child records (call them A and B models).
In the Admin, when the user adds an A record, some B records get added
automatically.
The next A record to get added does much the same but if there are any B
duplicates it doesn't try to add those but instead just adds its mark to
a special field in the B record which is already there.
My code - which from embedded print statements appears to be doing
exactly what I want - will either delete the B record or just remove the
mark previously added. Eventually when the last A record is deleted the
idea is that the last B records will go at the same time.
Unfortunately, at the final hurdle we get the ValidationError at line
988 in to_python.
The local vars nominate ...
self <django.forms.models.ModelChoiceField object at 0x00F5DE70>
value u'251'
key 'pk'
... and that is the pk of the A record which triggers the Item code via
a pre_delete signal.
Summarising:
- the deletion/mark removal method lives in the Item model
- the pre-delete signal is detected in the A record
- the signal connects a stub method in the A record
- the stub method in the A record calls the Item method
- the Item method iterates over a filtered queryset of B records and
uses the passed value (the aforesaid mark from the A record) to decide
whether to delete the B record or just remove the mark and save it
None of my code appears in the TraceBack so I assume the Admin is trying
to delete the A record. I've tried both pre_delete and post_delete
signals in the A record.
Why is it so?
Thanks for any hints
Mike
--
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.