Trying to Download a cvs file with choices field's Value

Hi, my cvs file is downloading perfectly, however, I want to display its real value, not its initials
for eg, this is what I get at the moment

And when I use get_myfield_display,
I get the following result saying …functools.partial(<bound method Model._get_FIELD_display of

I hope I make myself clear.
following is my code to download the cvs file

def checklist_csv(request, pk):
    checklist = CheckList.objects.filter(pk=pk)

    response = HttpResponse(content_type='text/csv')  
    response['Content-Disposition'] = 'attachment; filename="checklist.csv"'


    writer = csv.writer(response)
    writer.writerow([
        'Boat Name', 'Boat Captain', 'Hull Condition', 'Hull Remarks', 'Seat Conditin', 'Seat Remarks'
    ])

    for i in checklist:
        writer.writerow([
            i.boat_name, i.created_by, i.get_hull_condition_display, i.hull_remarks, i.get_seat_condition_display, i.seat_remarks
        ])

    return response

Hey there!
get_something_display it’s a function, and need to be called.
This may look weird if you were just using this on templates, but on templates you don’t need to call the function, because you don’t have that syntax available. So on the python side, you must call the function get_something_display().

thanks, I think I’ve just figured it out, when I download my content to an cvs file, it is downloading the content that is already populated in the db, so I don’t think there is a way to get my results as I want.

You can display the human readable value.

You must change the value here:

To
i.get_hull_condition_display()
and the same for the
i.get_seat_condition_display()

Yes it does, work, thanks :pray: :pray:… can I ask why did it work?, I thought the info is derived from the pre-populated database

The informations indeed comes from the database.
But in this case you’re loading the Model instances.

These instances will be populated with the db values, but they’re more than that.
Since the fields: hull_condition and seat_condition have a choices attribute defined, django creates for you a method get_fieldname_display that can be used to translate a database value to a human readable value. This is documented here.

Thanks again for the explanation, and pointing to the right documentation.