On Tue, May 5, 2009 at 6:43 PM, ringemup <[email protected]> wrote: > > I've set up contrib.comments as an inline form on a related model in > the Django admin. I'd like to hide a few fields (e.g. "Site") from > the user and automatically populate them on save. I can't see a way > to go about populating them, though, so I'm getting integrity errors > such as "Column 'site_id' cannot be null". > > Can anyone please point me in the right direction, or the right > section of the documentation? > > Thanks!
You have a few options to go about doing this. The first and most easy way is by either removing the constraint that the field must exist or create a default site in the field. Both of these options can be done at the model level: http://docs.djangoproject.com/en/dev/ref/models/fields/#null and http://docs.djangoproject.com/en/dev/ref/models/fields/#default The other thing you can do it change the form for the admin to populate the field using a default value or during the save method. You can replace the form by defining it in the form attribute in your ModelAdmin: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form And you can change the save method in the form: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-methodor you can add an initial value to the field: http://docs.djangoproject.com/en/dev/ref/forms/fields/#initial I hope that helps, Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

