I'm running into a problem with the save() method in which I need
Django to update items in Model_B when an item from Model_A is saved.
The problem is that I save Model_A but Model_B is not updated.
However, if I save Model_A a second time (without changing anything)
then Model_B is updated.

Here's the setup:

Model_A is ARTICLES and Model_B is PHOTOS. ARTICLES contains a many-to-
many field for PHOTOS so that multiple photos can be attached to each
article. PHOTOS are attached to ARTICLES via an intermediary table
that is an inline table in the ARTICLES admin page.

When I save an article, I need the following to happen:

1) PHOTOS needs to be updated with info from ARTICLES, such as
publish_datetime. This is necessary to make sure that the photo's
publish_datetime is synced to the article. Photos do not have
publish_datetime set until they are attached to an article. In other
words, orphaned photos will not be published.

2) In the event that a photo is removed from an article, I need that
orphaned article to have its publish_datetime set to None. In order to
accomplish this, I wrote a function called clean_orphaned_photos that
queries PHOTOS for all photos with a publish_datetime and then queries
the intermediary model for each of the results to see if they also
exist there (which means they are attached to an article). If not,
they are wiped.

If #1 takes place in both the ARTICLES and the intermediary model's
save() then this works. #2, however, only takes place when an article
is saved twice. It's as if the intermediary table isn't updated before
#2 executes.

So, my questions are:

1) Should I put the functions for #1 and #2 in the ARTICLES save() or
in the intermediary model's save()?

2) Why would these functions require that I save an article two times
before they update the data?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to