Consider the following Django models:
class Host(models.Model):
# This is the hostname only
name = models.CharField(max_length=255)
class Url(models.Model):
# The complete url
url = models.CharField(max_length=255, db_index=True, unique=True)
# A foreign key identifying the host of this url
# (e.g. for http://www.example.com/index.html it will
# point to a record in Host containing 'www.example.com'
host = models.ForeignKey(Host, db_index=True)
I also have this form:
class UrlForm(forms.ModelForm):
class Meta:
model = Urls
The problem is the following: I want to compute the value of the host field automatically, so I don't want it to appear on the HTML form displayed in the web page.
If I use 'exclude' to omit this field from the form, how can I then use the form to save information in the database (which requires the host field to be present) ?