Created
August 26, 2011 03:38
-
-
Save skull-squadron/1172627 to your computer and use it in GitHub Desktop.
Customizing django admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
from django.db import models | |
from django.contrib.sites.models import Site | |
class DomainField(models.TextField): | |
def valdiate(self, value): | |
" DNS domain names are always blah.something." | |
super(DomainField, self).validate(value) | |
if len(value.split('.')) < 2: | |
raise ValidationError | |
default_error_message = { | |
'invalid': (u'Enter a valid domain with at least a dot (.), unicode allowed.'), | |
} | |
class CustomSite(Site): | |
domain = DomainField(help_text="This is the customer's domain that is to be accelerated.") | |
enabled = models.BooleanField(help_text="This controls whether the varnish site is actually enabled.",default=True) | |
# end of models.py | |
# admin.py | |
from models import CustomSite | |
from django.db import models | |
from django.contrib import admin | |
from django.contrib.sites.admin import SiteAdmin | |
from django.contrib.sites.models import Site | |
class CustomSiteAdmin(SiteAdmin): | |
pass | |
admin.site.unregister(Site) | |
admin.site.register(CustomSite, CustomSiteAdmin) | |
# end of admin.py | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fairly broken :(