Chris H. wrote:
> Greetings all,
>
> I'm trying to figure out the best DRY way of doing this.  I want to
> have a comments field on several of my models.  The idea behind this
> field is  that it would not actually be stored in the database,
> instead it would be appended to another field with a timestamp and the
> user.  Thus the database storage would look something like:
>
> ----- 17-JUN-2008 13:42 Bob -----
> This is Bob's comment that is stored away and not overwritten by
> Chris's below...
>
> ----- 18-JUN-2008 17:25 Chris -----
> Here is a comment by Chris...he only entered this
>
> The non-DRY way of doing this I imagine would be overriding the save
> function on my models.  I thought maybe I could do this with a custom
> field, but maybe not?
>
> Any thoughts and comments from the folks much smarter then me?? :)
>
> -C
>   
Hi Chris,

May be you can try this model :

class Comment(models.Model):
    comment = models.TextField(max_length=300)
    added_by = models.CharField(max_length=25)   #or a FK to auth.users
    dateadded = models.DateTimeField(auto_now_add=True)

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()

    content_object = generic.GenericForeignKey()

    def __unicode__(self):
        return self.comment

    class Meta:
        ordering = ["dateadded"]
       
You have to include 'django.contrib.contenttypes' in your INSTALLED_APPS 
though

HTH

Regards Ganesh



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to