Ticket #7287: newforms-initial-model.diff
File newforms-initial-model.diff, 821 bytes (added by , 16 years ago) |
---|
-
django/newforms/forms.py
278 278 attributes passed as attrs. If no widget is specified, then the 279 279 field's default widget will be used. 280 280 """ 281 from django.db import models 281 282 if not widget: 282 283 widget = self.field.widget 283 284 attrs = attrs or {} … … 288 289 data = self.form.initial.get(self.name, self.field.initial) 289 290 if callable(data): 290 291 data = data() 292 elif isinstance(data, models.Model): 293 data = data.pk 291 294 else: 292 295 data = self.data 293 296 return widget.render(self.html_name, data, attrs=attrs)