'If we have a tag, then we\'ll prepopulate our instance with the fields we\'d expect it
to have based on the tag. tag_key, tag_category, tag_type, and tag_data all refer to
the corresponding tag fields. The initial data of the form fields will similarly be
populated.'

def __init__(self, *args, **kwargs):

    super(TagForm, self).__init__(*args, **kwargs)
    tagkey = None
    tagcategory = None
    tagtype = None
    tagdata = None
    if hasattr(self.instance, 'tag'):
        tagkey = self.instance.tag.db_key
        tagcategory = self.instance.tag.db_category
        tagtype = self.instance.tag.db_tagtype
        tagdata = self.instance.tag.db_data
        self.fields['tag_key'].initial = tagkey
        self.fields['tag_category'].initial = tagcategory
        self.fields['tag_type'].initial = tagtype
        self.fields['tag_data'].initial = tagdata
    self.instance.tag_key = tagkey
    self.instance.tag_category = tagcategory
    self.instance.tag_type = tagtype
    self.instance.tag_data = tagdata
