I am struggling to extend the django.contrib.sites.admin. I am having a difficult time finding how to add a field to the sites admin page due to the fact that django.contrib.sites knows nothing of my foreign model. Is there an easy way which I am overlooking which would allow me to add the field “derp” from the following example to the sites admin? Do I have to extend django.contrib.sites.models safe/etc functionality to accomplish this? Thanks much.
class Herp(models.Model):
site = models.ForeignKey(Site)
derp = models.CharField(blank=True, max_length=15)
Edit: I should mention that I have the admin.py file with a class extending SiteAdmin. I understand the admin.site.unregister and admin.site.register. I just do not know how to include a field with a foreign key relation back to django.contrib.sites.
Inlines would do that. You can define
HerpInlineAdmin, add it to theinlinesattribute on yourSiteAdmin, then unregisterSite, and register it again with newSiteAdmin.Although this won’t actually add anything to the
Site‘s admin form, thederpfield will be present on Site’s admin page as an inline.