2

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.

wilbbe01
  • 1,931
  • 1
  • 24
  • 38
  • Have you thought of inlines? You can define `HerpInlineAdmin`, add it to the `inlines` attribute on your `SiteAdmin`, then unregister `Site`, and register it again with new `SiteAdmin`. Your field then will be present on Site admin page. – Anton Strogonoff Jun 08 '11 at 11:59
  • @Anton: yes, that is what I wanted. I guess I was concentrating too much on the fact I was wanting to add to a preexisting admin page I had no control over. That combined with the fact I didn't have the model pk set up like I should which also helped. If you want to post your answer as an answer I'll give you a check. Thanks. – wilbbe01 Jun 15 '11 at 22:31

1 Answers1

2

Inlines would do that. You can define HerpInlineAdmin, add it to the inlines attribute on your SiteAdmin, then unregister Site, and register it again with new SiteAdmin.

Although this won't actually add anything to the Site's admin form, the derp field will be present on Site's admin page as an inline.

Anton Strogonoff
  • 32,294
  • 8
  • 53
  • 61