[Answer]-Creating a representation of an object when no string to work with (python, django)

1👍

The string representation can be anything you like. It doesn’t even have to be a field on the model, although obviously that would make it pretty useless.

But of course you can use the date and/or the integer, as long as you convert them to a string first. So one good representation might be:

def __str__(self):
    return 'Worked %s hours on %s' % (self.time_worked, self.date_loggged)

or anything else that makes sense for your use case.

Leave a comment