Re: ModelAdmin, custom field: default value?

2011-06-28 Thread momo2k
Thanks, working :) def __init__(self, *args, **kwargs): super(MealModelForm, self).__init__(*args, **kwargs) try: instance = kwargs['instance'] self.fields['price'].initial = instance.price() except (KeyError, AttributeError): pass

Re: ModelAdmin, custom field: default value?

2011-06-28 Thread Marc Aymerich
On Tue, Jun 28, 2011 at 10:27 AM, Marc Aymerich wrote: > On Mon, Jun 27, 2011 at 11:03 PM, momo2k wrote: >> Hello, >> >> Is there a way to set dynamic default values for custom fields in the >> admin? >> >> Description of the problem: >> >> #

Re: ModelAdmin, custom field: default value?

2011-06-28 Thread Marc Aymerich
On Mon, Jun 27, 2011 at 11:03 PM, momo2k wrote: > Hello, > > Is there a way to set dynamic default values for custom fields in the > admin? > > Description of the problem: > > # models.py > # there are two models > class Meal(models.Model): >    name = ... > >    def

ModelAdmin, custom field: default value?

2011-06-27 Thread momo2k
Hello, Is there a way to set dynamic default values for custom fields in the admin? Description of the problem: # models.py # there are two models class Meal(models.Model): name = ... def check_new_price(self, price): # checks if the price is new and creates a new price if