36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
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)
|