March 2020
Intermediate to advanced
608 pages
17h 17m
English
The following steps will show you how to switch from a foreign key relation to a many-to-many relation, while preserving the already existing data:
# myproject/apps/ideas/models.pyfrom django.db import modelsfrom django.conf import settingsfrom django.utils.translation import gettext_lazy as _from myproject.apps.core.model_fields import ( MultilingualCharField, MultilingualTextField,)class Idea(models.Model): title = MultilingualCharField( _("Title"), max_length=200, ) content = MultilingualTextField( _("Content"), ) category = models.ForeignKey( "categories.Category", verbose_name=_("Category"), blank=True, null=True, on_delete=models.SET_NULL, related_name="category_ideas", ...