[Answer]-How do I edit an object if it exist or create an object that doesn't exist in Django?

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

Leave a comment