Bring Coffee Bring Beer
Bring Coffee Bring Beer

Reputation: 1121

Setting default value based on database in DJango

Good evening,

I am new to Django and am working on a sort of ticketing app. My app has three models, Ticket, Status, & Notes.

When displaying the ticket details, I have a form to add a Note. What I want to do is to add to the form a drop down that is set to the current status value of the ticket. When creating the form, how do I pass in the current status value to the form and use it as the default value?

Thanks.

Upvotes: 1

Views: 65

Answers (1)

VMatić
VMatić

Reputation: 996

You can set it when calling the form constructor in your view:

form = NoteForm(initial={'status': ticket.status})

Upvotes: 3

Related Questions