Monday, May 31, 2010

Help: Custom ManyRelatedManager Behavior

Hi, I am having trouble getting the behavior I would like from a
ManyRelatedManager.

I have a many to many relationship with User and ModelB, with a join
table ModelJ. Instead of deleting items in my database, I am simply
marking them as deleted. I have a custom manager that filters out
deleted objects as a first step. Everything was working fine until I
ran across the following problem:

To access objects of ModelB that a belong to a User, say user1, I use
user1.modelb_set. Let's say user1.modelb_set returns modelb1, modelb2,
and modelb3. Finally let modelj2 describe the relationship between
user1 and modelb2.

If I set modelj2.deleted = True, I was hoping that user1.modelb_set
would only return modelb1 and modelb3. Unfortunately it still returns
all three modelb objects. I guess this is because the "deleted"
attribute is being set on the join table, and not the ModelB table.

Does anybody know how to set up custom behavior for a
ManyRelatedManager? Basically, I would like to break links between
User and ModelB by marking their ModelJ link as deleted, not actually
deleting it from the database.

Thank you,
Tim

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment