1👍
✅
Maybe you can use update_or_create
method (described here https://docs.djangoproject.com/en/dev/ref/models/querysets/#update-or-create)
Something like this:
defaults = {'rating': 5}
Rating.objects.update_or_create(restaurant_id=1, user_id=1, defaults=defaults)
If rating object in this restaurant does not exists, it will create it. If exists, rating will be updated.
Note: this method is new in django 1.7
Source:stackexchange.com