Could someone please point out my mistake?
def clean_out(self):
child_lst = list(Child.objects.filter(master=self.master,
tags=self.mark))
for child in child_lst:
child.delete()
child_lst = list(Child.objects.filter(master=self.master,
tags__contains=self.mark))
for child in child_lst:
marks = child.tags.split()
marks = marks.remove(self.mark)
child.tags = ' '.join(marks)
child.save()
The "self" in this case is an instance of the Parent class and
clean_out() is a Parent model method. Both Parent and Child have a
foreign key relationship with the Master model. Nothing has a foreign
key pointing to either Parent or Child.
Parent.clean_out() method is connected to the pre_delete signal of the
Parent model.
The purpose of the method is more or less documented below.
I've tried this a number of different ways and always get the "Select a
valid choice ..." error mentioned below.
On 4/02/2013 6:14pm, Mike Dewhirst wrote:
This is the error ... Select a valid choice. That choice is not one of
the available choices.
I want to delete a bunch of "child" records when a "parent" record is
deleted. While I'm using that terminology they are not actually related
in the usual sense. All however are in foreign key relationships with
the same owner/master.
The child records all know which parents they have because the parent
added its mark to a field in the child when the child record got created
and linked to the master. In fact if that child had been added by
another parent, the next parent just adds its mark instead of adding
another child.
When a parent gets deleted from the master, its mark is removed from all
the child records it was involved with and if it was the only mark the
child gets deleted too. Or at least that is what I want to happen.
My question is:
In overview, how should I be doing this?
At the moment I'm trying to do it all via model methods calling various
managers because it feels like the right place to do it.
I have tried to make a custom manager with use_for_related_fields = True
but still get the same error.
Thanks for any help
Mike
--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.