On 16 juin, 20:07, Micky Hulse <rgmi...@gmail.com> wrote: > Hello, > > Just curious what the rule-of-thumb is for when it comes to using > model methods vs. properties. For example: > > [code] > > @property > def is_modified(self): > if self.modified > self.created: > return True > return False
<ot> This could be written much more simply as "return self.modified > self.created" </ot> > def get_separator(self): > return ' :: ' In this case (returning a constant), it would be much simpler to make it a class (or instance) attribute. > [/code] > > I feel like I have seen so many examples of methods and properties > that return the same type of stuff, I am just confused about when to > use one over the other. Properties are for computed attributes - that is, things that are the semantically (conceptually, whatever) attributes, but requires any computation, either on get, set or del. But well, if you prefer java- like getters/setters, then choice is yours... Depends on the programmer's background, and of course of whether the code was written before new-style classes and the descriptor protocol.... -- 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.