Changes between Version 2 and Version 3 of Ticket #28268, comment 2
- Timestamp:
- Jun 3, 2017, 12:41:44 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28268, comment 2
v2 v3 18 18 title = models.CharField() 19 19 20 def save(self): 21 if not self.id or self.has_chaged(): # newly created or changed 22 del self.model.related_count 23 24 def delete(self): 25 del self.model.related_count 26 27 20 28 21 29 >>> model = ModelA() 22 >>> model.related_count ()30 >>> model.related_count 23 31 0 # calls first time 24 >>> model.related_count ()32 >>> model.related_count 25 33 0 # does not call 26 34 … … 30 38 >>> rel.save() 31 39 32 >>> model.related_count ()40 >>> model.related_count 33 41 1 # calls first time, because rel added 34 >>> model.related_count ()42 >>> model.related_count 35 43 1 # does not call 36 44 37 >>> model.related_content ()45 >>> model.related_content 38 46 Text # calls first time 39 >>> model.related_content ()47 >>> model.related_content 40 48 Text # does not call 41 49 42 50 >>> rel.title = "New Text" 43 51 >>> rel.save() 44 >>> model.related_content ()52 >>> model.related_content 45 53 New Text # calls first time, because rel changed 46 >>> model.related_content ()54 >>> model.related_content 47 55 New Text # does not call 48 >>> model.related_count ()56 >>> model.related_count 49 57 1 # calls again, because rel changed 50 58 51 59 >>> rel.delete() 52 >>> model.related_count ()60 >>> model.related_count 53 61 0 # calls, because rel removed 54 >>> model.related_content ()62 >>> model.related_content 55 63 # calls, return nothing 56 64 }}}