Consider the following Django models:
class Host(models.Model):
name = models.CharField(max_length=255)
class Url(models.Model):
url = models.CharField(max_length=255, db_index=True, unique=True)
host = models.ForeignKey(Host, db_index=True)
I also have this form:
class UrlForm(forms.ModelForm):
class Meta:
model = Urls
The problem is this: I want to automatically calculate the value of the host field, so I do not want it to be displayed in HTML form displayed on the web page.
If I use 'exclude' to omit this field from the form, how can I use the form to store information in the database (which requires a host field)?
source
share