[Django]-Django 1.1 forms, models and hiding fields

3👍

Use commit=False:

result = form.save(commit=False)
result.host = calculate_the_host_from(result)
result.save()

1👍

You can use exclude and then in the forms “clean” method set whatever you want.

So in your form:

class myform(models.ModelForm):
   class Meta:
       model=Urls
       exclude= ("field_name")
   def clean(self):
      self.cleaned_data["field_name"] = "whatever"
      return self.cleaned_data

Leave a comment