Is it correct to put logic that alters instances within model methods?
The examples in the django docs are all methods that don’t alter the actual instance but rather just return some specific information.
ie. model method examples from django docs:
def is_midwestern(self):
"Returns True if this person is from the Midwest."
return self.state in ('IL', 'WI', 'MI', 'IN', 'OH', 'IA', 'MO')
what I would like to do
def publish(self):
"Publishes this video."
self.published = True
# some other related business logic here
Is that considered ok? Or should this go somewhere else?
Yes, it is good object-oriented design to abstract operations on an object as methods, particularly if they only affect that object.
That isn’t necessary if you’re just doing trivial getter/setter methods (we’re not writing Java here…), but since you mention that there is other business logic involved, I think that’s a good design decision.