Changes between Version 2 and Version 3 of Ticket #28268, comment 2


Ignore:
Timestamp:
Jun 3, 2017, 12:41:44 PM (7 years ago)
Author:
Özer Sahin

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28268, comment 2

    v2 v3  
    1818    title = models.CharField()
    1919
     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
    2028
    2129>>> model = ModelA()
    22 >>> model.related_count()
     30>>> model.related_count
    23310  # calls first time
    24 >>> model.related_count()
     32>>> model.related_count
    25330  # does not call
    2634
     
    3038>>> rel.save()
    3139
    32 >>> model.related_count()
     40>>> model.related_count
    33411  # calls first time, because rel added
    34 >>> model.related_count()
     42>>> model.related_count
    35431  # does not call
    3644
    37 >>> model.related_content()
     45>>> model.related_content
    3846Text  # calls first time
    39 >>> model.related_content()
     47>>> model.related_content
    4048Text  # does not call
    4149
    4250>>> rel.title = "New Text"
    4351>>> rel.save()
    44 >>> model.related_content()
     52>>> model.related_content
    4553New Text  # calls first time, because rel changed
    46 >>> model.related_content()
     54>>> model.related_content
    4755New Text  # does not call
    48 >>> model.related_count()
     56>>> model.related_count
    49571  # calls again, because rel changed
    5058
    5159>>> rel.delete()
    52 >>> model.related_count()
     60>>> model.related_count
    53610  # calls, because rel removed
    54 >>> model.related_content()
     62>>> model.related_content
    5563  # calls, return nothing
    5664}}}
Back to Top