I'm looking to assign a default value using a method inside model:
class Discussion(models.Model):
# attributes ...
def __str__(self):
return str(self.id) + ". " + self.title
def class_name(self):
return self.__class__.__name__
discussion_type = models.CharField(max_length = 50, default = self.class_name())
class TechDiscussion(Discussion):
# ...
class ScienceDiscussion(Discussion):
# ...
In my Django app, users can only create science or tech discussions. Thus discussion_type should be either "TechDiscussion" or "ScienceDiscussion".
Server returns error NameError: name 'self' is not defined, referring to the default value assigned to discussion_type.
Supermodel.