views:

15

answers:

1

Is there a better way of doing something like this:

if status == 1:
    mymodel.drafted_date = date.today()
if status == 2
    mymodel.registered_date = date.today()
if status == 3
    mymodel.reported_date = date.today()
if status == 4
    mymodel.checked_date = date.today()
if status == 5
    mymodel.end_date = date.today()

I thought there might be something like:

field_to_update = get_the_field_from_a_list_somewhere()
mymodel[field_to_update] = date.today()

(Sorry .... I is a bit of a noob)

+1  A: 
statusmap = {1: 'drafted_date', 2: 'registered_date', ...}

  ....

setattr(mymodel, statusmap[status], date.today())
Ignacio Vazquez-Abrams
Hi Ignacio. Thanks for that. That's going to help a lot.
alj