Django, problems with overriding model in sites packages
Question: i got problems with overriding of model "Sites", that contains in Sites
framefork. I have a form with "Sites" on my site, i need to display names of
Sites, not Site.domain, i'm override model, route it to same DB table in
"Meta" class and get error, that i cant to understand, code here:

**Model:**

    
    
    @python_2_unicode_compatible
    class Site(models.Model):
    
    domain = models.CharField(_('domain name'), max_length=100)
    name = models.CharField(_('display name'), max_length=50)
    objects = SiteManager()
    
    class Meta:
        db_table = 'django_site'
        verbose_name = _('site')
        verbose_name_plural = _('sites')
        ordering = ('domain',)
    
    def __str__(self):
        return self.domain
    
    def save(self, *args, **kwargs):
        super(Site, self).save(*args, **kwargs)
        # Cached information will likely be incorrect now.
        if self.id in SITE_CACHE:
            del SITE_CACHE[self.id]
    
    def delete(self):
        pk = self.pk
        super(Site, self).delete()
        try:
            del SITE_CACHE[pk]
        except KeyError:
            pass
    

**My overrided model:**

    
    
    from django.contrib.sites.models import Site
    from django.utils.translation import ugettext_lazy as _
    
    
    class NamedSite(Site):
        def __str__(self):
            return self.name
    
    class Meta:
        db_table = 'django_site'
        verbose_name = _('site')
        verbose_name_plural = _('sites')
        ordering = ('domain',)
    

**and Error**

    
    
    DatabaseError at <my url>
    
    ERROR:  Column django_site.site_ptr_id doesn't exist
    LINE 1: ...ROM "django_site" INNER JOIN "django_site" T2 ON ("django_si...
    


Answer: Subclassing the model is an example of [model
inheritance](https://docs.djangoproject.com/en/dev/topics/db/models/#multi-
table-inheritance). It is not possible to 'override the model and route to the
same db table'.

A better approach would be to subclass
[`ModelChoiceField`](https://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield),
and override `label_from_instance` to display a site instance as you wish.
Then use your model choice field to select the site in your form.

