March 2020
Intermediate to advanced
608 pages
17h 17m
English
First, create a likes app and add it to your INSTALLED_APPS. Then, set up a Like model, which has a foreign-key relation to the user who is liking something and a generic relationship to any object in the database. We will use object_relation_base_factory, which we defined in the Creating a model mixin to handle generic relations recipe in Chapter 2, Models and Database Structure. If you don't want to use the mixin, you can also define a generic relation in the following model yourself:
# myproject/apps/likes/models.pyfrom django.db import modelsfrom django.utils.translation import ugettext_lazy as _from django.conf import settingsfrom myproject.apps.core.models import ( CreationModificationDateBase, object_relation_base_factory, ...
Read now
Unlock full access