django - prepopulated field and function() -


as per understanding, pre-populated fields shouldn't include foriegnkey. thought of workaround.

in model .. defined function name getname()

def getname(self):     t1 = str(self.team_one)     t2 = str(self.team_two)     t1t2 = t1 + ' vs ' + t2     return t1t2 

and thought of calling in admin .. how doing it.

prepopulated_fields = { 'name': ('getname()',)} 

it should solve problem, django says.

exception type: improperlyconfigured exception value:     'fixtureadmin.prepopulated_fields['name'][0]' refers field 'getname' missing model 'fixture'. 

is there work around it, or should drop idea?

//mouse

prepopulated_fields slugs; it's not generalized way give field default value.

you'll have write own javascript this. following should trick:

$('#id_team_one, #id_team_two').change(function(){     var $team1 = $('#id_team_one');     var $team2 = $('#id_team_two');     if ($team1.val() && $team2.val()) {         var team1_selected = $(':selected', $team1).text();         var team2_selected = $(':selected', $team2).text();         $('#id_name').val(team1_selected + ' vs ' + team2_selected);     } }); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -