I know that a model object string representation can be achieved by adding
class Company(models.Model):
name = models.CharField()
email = models.EmailField(unique=True)
def __str__(self):
return self.name
But this is the representation of an object of Company but not the model class itself. Meaning if I create an object
obj = Company(name='string_repr', email='example@example.com')
print(obj)
would result in 'string_repr'
which is as expected since Im getting the string representation of the object, not the class/ model. However I noticed that during a CreateView
form validation in case if there already is an object of the model with the same email Django returns an error message that there already is a Company with such an email (picture is not in English but the underlined section is the only relevant part).
I suppose the error message is taking the class name and inputting it in the message, but is there a way how to alter the string representation of the model (class) name? Its needed for translation purposes. I guess I could just rename the class names to local language but that doesn't seem right.