Permalink
Browse files

added add_flag helper function

git-svn-id: http://django-flag.googlecode.com/svn/trunk@4 6223c904-8705-11dd-a5c9-f1483cedc3eb
  • Loading branch information...
jtauber committed Sep 20, 2008
1 parent b2340b3 commit bc65e26af8ca2bddd1874412deabd73fdc5c0170
Showing with 16 additions and 0 deletions.
  1. +16 −0 flag/models.py
View
@@ -33,3 +33,19 @@ class FlagInstance(models.Model):
user = models.ForeignKey(User)
when_added = models.DateTimeField(default=datetime.now)
when_recalled = models.DateTimeField(null=True) # if recalled at all
+
+
+def add_flag(flagger, content_object, content_creator):
+
+ # check if it's already been flagged
+ try:
+ flagged_content = FlaggedContent.objects.get(content_object=content_object)
+ except FlaggedContent.DoesNotExist:
+ creator = content_creator
+ flagged_content = FlaggedContent(content_object=content_object, creator=creator)
+ flagged_content.save()
+
+ flag_instance = FlagInstance(flagged_content=flagged_content, user=flagger)
+ flag_instance.save()
+
+ return flag_instance

0 comments on commit bc65e26

Please sign in to comment.