Hi, I would like to track the viewing history for users to my site to see which blog entries are being viewed by whom. And I would like to track the user who is viewing it *IF* they are logged in, otherwise I would like to ignore the user field (see models below)
[models.py] class Entry(models.Model): title = models.CharField(maxlength=250) slug = models.SlugField( maxlength=250, prepopulate_from=('title'), unique_for_date='pub_date' ) body = models.TextField() pub_date = models.DateTimeField(default=datetime.now()) class ViewHistory(models.Model): entry = models.ForeignKey(Entry) user = models.ForeignKey(User, blank=True) timestamp = models.DateTimeField(auto_now=True,editable=False) The problem is that I cannot save the ViewHistory unless the user is logged in. Apparently Django does not allow a blank user field (even it is specified in the model) and I get the following error: (1048, "Column 'user_id' cannot be null") If I try to use an AnonymousUser object then Django complains: ValueError: Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0xab7e84c>": "ViewHistory.user" must be a "User" instance. Can anyone help me understand how to have a model with an optional foreign key to the django.contrib.auth.models User object? Thanks, R --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---