0
votes

I'm using django-notification to create notifications. based on it's documention I putted:

url(r'^inbox/notifications/', include(notifications.urls, namespace='notifications')),

in my urls.py. I generate a notification for test by using this in my views.py:

guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')

and I can easily get the number of unread notification in this url:

http://127.0.0.1:8000/inbox/notifications/api/unread_count/

it return {"unread_count": 1} as I want. but with /api/unread_list/ I can not to get the list of notifications and I get this error:

ValueError at /inbox/notifications/
invalid literal for int() with base 10: '<property object at 0x7fe1b56b6e08>'

As I beginner in using django-notifications any help will be appreciated.

Full TraceBack

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/inbox/notifications/api/unread_list/

Django Version: 2.0.2 Python Version: 3.5.2 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.forms', 'rest_framework', 'allauth', 'allauth.account', 'allauth.socialaccount', 'guardian', 'axes', 'django_otp', 'django_otp.plugins.otp_static', 'django_otp.plugins.otp_totp', 'two_factor', 'invitations', 'avatar', 'imagekit', 'import_export', 'djmoney', 'captcha', 'dal', 'dal_select2', 'widget_tweaks', 'braces', 'django_tables2', 'phonenumber_field', 'hitcount', 'el_pagination', 'maintenance_mode', 'notifications', 'mathfilters', 'myproject_web', 'Order', 'PhotoGallery', 'Search', 'Social', 'UserAccount', 'UserAuthentication', 'UserAuthorization', 'UserProfile'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django_otp.middleware.OTPMiddleware', 'maintenance_mode.middleware.MaintenanceModeMiddleware']

Traceback:

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner 35. response = get_response(request)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 128. response = self.process_exception_by_middleware(e, request)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 126. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/notifications/views.py" in live_unread_notification_list 164. if n.actor:

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/fields.py" in get 253. rel_obj = ct.get_object_for_this_type(pk=pk_val)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/models.py" in get_object_for_this_type 169. return self.model_class()._base_manager.using(self._state.db).get(**kwargs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py" in get 394. clone = self.filter(*args, **kwargs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py" in filter 836. return self._filter_or_exclude(False, *args, **kwargs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py" in _filter_or_exclude 854. clone.query.add_q(Q(*args, **kwargs))

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py" in add_q 1253. clause, _ = self._add_q(q_object, self.used_aliases)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py" in _add_q 1277. split_subq=split_subq,

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py" in build_filter 1215. condition = self.build_lookup(lookups, col, value)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py" in build_lookup 1085. lookup = lookup_class(lhs, rhs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py" in init 18. self.rhs = self.get_prep_lookup()

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py" in get_prep_lookup 68. return self.lhs.output_field.get_prep_value(self.rhs)

File "/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/fields/init.py" in get_prep_value 947. return int(value)

Exception Type: ValueError at /inbox/notifications/api/unread_list/ Exception Value: invalid literal for int() with base 10: ''

3
What are your Python, Django, and Django-notification versions?Selcuk
python3, Django==2.0.2, and django-notifications-hq==1.4.0 @SelcukSirSaleh
Do you have the full traceback?Cole
@Cole I just added it.SirSaleh

3 Answers

1
votes

The actor_object_id needs to be a CharField to support UUID based primary keys.

0
votes

oops! It was my mistake. I Finally find out what was the problem. actor_object_id was the field of notifications_notification table, which User.objects.get(username = 'SirSaleh') saved in it. It should be Interger (user_id of actor).

So I dropped previous table changed instance to User.objects.get(username = 'SirSaleh') to User ID. Problem solved.

So Why type of actor_object_id is CharField (varchar)? (at least I don't know) ;))

0
votes

This is old, but I happen to know the answer.

In your code, you wrote:

guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')

You express that you want guy to be your sender However, in notify.send, you marked the sender as a generic User object, not guy.

So, change your code to:

guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=guy, recipient=guy, verb='you visted the site!')

Notifications will take the user object guy, extrapolate the ID and store it in the database accordingly.