holy moly part 2 Fri, 23 Mar 2012 16:47:02 -0400

Thought someone might be interested in seeing the triggers ... basically how you should handle this problem or signalling / triggering a function upon saving a document (yes I know not sql appropriate terminalogy). My lack for love for SQL is better left for another blog post.

<quote>

-------------------------------- blog/models.py --------------------------------

index 00cb4b6..dd06100 100644

@@ -22,7 +22,7 @@ class Entry(models.Model):

     """

     author          = models.ForeignKey(User)

     active          = models.BooleanField(default=False)

-    tags            = models.ManyToManyField(Tag)

+    tags            = models.ManyToManyField(Tag, blank=True, null=True)

     date_created        = models.DateTimeField(default=datetime.datetime.now)

     date_last_modified  = models.DateTimeField(default=datetime.datetime.now)

     title           = models.CharField(max_length=64)

@@ -39,12 +39,6 @@ class Entry(models.Model):

         """ using rules return boolean if this entry accepts comments """

         return self.days_online() <= 90

 

-    def save(self):

-        self.slug = '-'.join(self.title.split())#And clean title, and make sure this is unique.

-        if len(self.slug) > 50:

-            self.slug = self.slug[:50]

-            super(Entry, self).save()

-

     def get_absolute_url(self):

         return "/blog/read/%s/" % self.slug

 

@@ -97,7 +91,7 @@ class Comment(models.Model):

 # --------------------- REGISTERING SIGNALS

 # --------------------- REGISTERING SIGNALS

 

-from django.db.models.signals import post_save, post_delete

+from django.db.models.signals import post_save, post_delete, pre_save

 

 def comment_delete_handler(signal, **kwargs):

     if kwargs['instance'].ip:

@@ -118,7 +112,15 @@ def comment_update_handler(signal, **kwargs):

                 "Someone posted a comment to an entry you commented on on http://www.modernninja.com%s" % kwargs['instance'].entry.get_absolute_url(),

                 'ModernNinja.com <no-reply@modernninja.com>',

                 [C.email_address],

-                fail_silently=True)

+                fail_silently=True

+                )

 

 post_save.connect(comment_update_handler, sender=Comment)

 post_delete.connect(comment_delete_handler, sender=Comment)

+

+def entry_slug_handler(instance, **kwargs):

+    instance.slug = '-'.join(instance.title.split())#And clean title, and make sure this is unique.

+    if len(instance.slug) > 50:

+        instance.slug = instance.slug[:50]

+

+pre_save.connect(entry_slug_handler, sender=Entry)

</quote>

1 comments. More...
holy moly Thu, 22 Mar 2012 10:10:43 -0400

It has been a LOOOONG time since I've posted to this site. The main reason is my own, just commented it out and moved it to a pre_save trigger.. all is well with the world now.

<quote>

 

-------------------------------- blog/models.py --------------------------------

index 0482a54..80a1917 100644

@@ -23,13 +23,21 @@ class Entry(models.Model):

  author = models.ForeignKey(User)

  active = models.BooleanField(default=False)

  tags = models.ManyToManyField(Tag)

- date_created = models.DateTimeField(default=datetime.datetime.now)

- date_last_modified = models.DateTimeField(default=datetime.datetime.now)

+ date_created = models.DateTimeField(default=datetime.datetime.now)

+ date_last_modified = models.DateTimeField(default=datetime.datetime.now)

  title = models.CharField(max_length=64)

  body = models.TextField()

 

+ slug = models.SlugField()

+

+ def save(self):

+ self.slug = '-'.join(self.title.split())#And clean title, and make sure this is unique.

+ if len(self.slug) > 50:

+ self.slug = self.slug[:50]

+         super(Entry, self).save()

+

  def get_absolute_url(self):

- return "/blog/read/%d/" % self.id

+ return "/blog/read/%s/" % self.slug

 

  def __str__(self):

  return str(self.title)

</quote>

 

3 comments. More...
bglug presentation on ipv6 Sat, 18 Jun 2011 10:04:28 -0400

Today I will be presenting at the BGLUG on IPv6. Come on our and learn a bit about IPv6 and the future of our internet.

0 comments. More...
iPad convert here Sun, 22 May 2011 22:20:22 -0400

Awww crap... I bought an iPad for my two year old... Now I'm addicted to the damned thing.

0 comments. More...
Woops Thu, 31 Mar 2011 11:02:57 -0400

Looks like I forgot to mention that earlier this month I gave a presentation on Django and high availability and distributed web applications at Codepalousa. Went well, with some great participation from the audience. The only negative I came away with was that it was a very Microsoft centric technology event. Not much room for FOSS. Luckily I was able to change that a little bit :)

0 comments. More...

  • About The Author
  • This is the definitive blog for the musings of Brian Smith. I've been a programmer / sys admin for most of my life. I don't have much to say, I work, I enjoy my family, and every once in awhile I'll dump a little something I want to keep track of here.

    Currently I am the CTO of DNS.com where we provide geolocation based authoritative DNS services for the masses. I also have been working on drafts that are submitted to the IETF to the dnsext working group.

    In the past I have been involved with organizing various user groups, including an off and on again 2600 group. Also I have been involved with the development of Seclude, an open source secure instant messaging platform as well as Sliker, a project that later developed into plasma for the KDE desktop environment.

    Additionally I am an avid home brewer making my own beer. Everything else should be below or to the left.

  • Disclaimer
  • The ideas and opinions expressed here are mine.
  • I'm a Linux and BSD user, and lean heavily toward the use of OSS vs certain other commercial solutions.

:= RSS =: