Source

django-pim / sitetracker / models.py

Full commit
Kevin Veroneau fffb63b 



































































from django.db import models
from pcbank.models import Payee
from projects.models import Project
from django.template.defaultfilters import slugify
from django.db.models.signals import post_save
from sitetracker.signals import clear_server_list

class HostingProvider(models.Model):
    company = models.CharField(max_length=60)
    slug = models.SlugField()
    payee = models.ForeignKey(Payee, blank=True, null=True)
    notes = models.TextField(blank=True)
    admin_url = models.URLField(blank=True, null=True)
    def __unicode__(self):
        return u"%s" % self.company
    def save(self, *args, **kwargs):
        self.slug = slugify(self.company)
        super(HostingProvider, self).save(*args, **kwargs)
    @models.permalink
    def get_absolute_url(self):
        return ('hostingprovider-view', [self.slug])
    @models.permalink
    def get_update_url(self):
        return ('hostingprovider-edit', [self.slug])

class Server(models.Model):
    name = models.CharField(max_length=20)
    slug = models.SlugField()
    ipaddr = models.IPAddressField(verbose_name='IP Address')
    provider = models.ForeignKey(HostingProvider, verbose_name='Hosting Provider')
    webshell = models.URLField(blank=True, null=True)
    notes = models.TextField(blank=True)
    def __unicode__(self):
        return u"%s" % self.name
    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Server, self).save(*args, **kwargs)
    @models.permalink
    def get_absolute_url(self):
        return ('server-view', [self.provider.slug, self.slug])
    @models.permalink
    def get_update_url(self):
        return ('server-edit', [self.provider.slug, self.slug])

class Domain(models.Model):
    name = models.CharField(max_length=60)
    server = models.ForeignKey(Server)
    projects = models.ManyToManyField(Project, blank=True, null=True)
    payee = models.ForeignKey(Payee, blank=True, null=True)
    admin_url = models.URLField(blank=True, null=True)
    notes = models.TextField(blank=True)
    def __unicode__(self):
        return u"%s" % self.name
    @models.permalink
    def get_absolute_url(self):
        return ('domain-view', [self.server.provider.slug, self.server.slug, self.name])
    @models.permalink
    def add_project_url(self):
        return ('domain-add-project', [self.server.provider.slug, self.server.slug, self.name])
    @models.permalink
    def rm_project_url(self):
        return ('domain-rm-project', [self.server.provider.slug, self.server.slug, self.name])
    @models.permalink
    def get_update_url(self):
        return ('domain-edit', [self.server.provider.slug, self.server.slug, self.name])

post_save.connect(clear_server_list, sender=HostingProvider)
post_save.connect(clear_server_list, sender=Server)
post_save.connect(clear_server_list, sender=Domain)