diff options
Diffstat (limited to 'links/models.py')
-rw-r--r-- | links/models.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/links/models.py b/links/models.py new file mode 100644 index 0000000..50319a2 --- /dev/null +++ b/links/models.py @@ -0,0 +1,35 @@ +from django.db import models +from main.models import Tag, Activity +from django.db.models.signals import post_save, post_delete + +class Bookmark(models.Model): + url = models.URLField(primary_key=True, max_length=255) + date = models.DateTimeField(auto_now_add=True) + name = models.CharField(max_length=255) + description = models.TextField() +# tags = models.ManyToManyField(Tag, null=True, blank=True) + priority = models.IntegerField(null=True, blank=True) + + def __unicode__(self): + return self.name + +def bookmark_saved_callback(sender, **kwargs): + if kwargs['created']: + acttype = 'add' + else: + acttype = 'edit' + + a = Activity(actcategory='link', + actdescription=kwargs["instance"].name, + acttype = acttype, + objpk = kwargs["instance"].pk) + a.save() + +def bookmark_deleted_callback(sender, **kwargs): + a = Activity(actcategory='link', + actdescription=kwargs["instance"].name, + acttype = 'delete') + a.save() + +post_save.connect(bookmark_saved_callback, sender=Bookmark) +post_delete.connect(bookmark_deleted_callback, sender=Bookmark) |