django-pim / sitetracker / models.py

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.