Portfolio.objects.order_by().order_by(
    'code', # first, cause we want to group by this value
    '-created' # descending order, latest / max will be first
).distinct('code')