How can a person extend django.contrib.sites.admin so as to include a field from a model with a foreign key pointing at sites?
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 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.
精彩评论