-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UPVOTE] convertir la clé étrangère Post en clé étrangère générique #354
Conversation
82b32c3
to
02e18b2
Compare
74bad72
to
031807a
Compare
031807a
to
4193123
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Très propre. Je n’ai pas testé fonctionnelement, mais le code semble bien 👍
for upvote in UpVote.objects.all(): | ||
upvote.content_object = upvote.post | ||
upvote.object_id = upvote.post_id | ||
upvote.content_type = ContentType.objects.get_for_model(upvote.post) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On pourrait sortir cette requête de la boucle pour accélérer la migration.
lacommunaute/forum_upvote/models.py
Outdated
verbose_name="Post", | ||
) | ||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) | ||
object_id = models.PositiveIntegerField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.djangoproject.com/en/4.2/ref/models/fields/#positivebigintegerfield
Par défaut, le projet semble utiliser les BigAutoField
s, donc un entier entre 1
et 2^64-1
.
https://github.com/betagouv/itou-communaute-django/blob/master/config/settings/base.py#L215
merci @francoisfreitag ! |
0275e3d
to
838986f
Compare
…dle data migration
838986f
to
96bb1b9
Compare
Description
🎸 Remplacer la clé étrangère
Post
dans le modèleUpVote
par uneGenericForeignKey
pour préparer l'upvote d'autres objets de la communauté (ie lesForum
)Type de changement
🚧 technique, fait suite à la PR #356
Points d'attention
🦺 dans le modele
UpVote
, transformer laForeignKey
versPost
enGenericForeignKey
🦺 migrer les données aller-retour
🦺 adapter les appels à
UpVoteFactory
et lesUpVote.objects.filter()
existants🦺 ajout d'une
GenericRelation
du modelePost
vers le modèleUpVote