Skip to content
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

Merged
merged 4 commits into from
Jul 25, 2023

Conversation

vincentporte
Copy link
Contributor

@vincentporte vincentporte commented Jul 18, 2023

Description

🎸 Remplacer la clé étrangère Post dans le modèle UpVote par une GenericForeignKey pour préparer l'upvote d'autres objets de la communauté (ie les Forum)

Type de changement

🚧 technique, fait suite à la PR #356

Points d'attention

🦺 dans le modele UpVote, transformer la ForeignKey vers Post en GenericForeignKey
🦺 migrer les données aller-retour
🦺 adapter les appels à UpVoteFactory et les UpVote.objects.filter() existants
🦺 ajout d'une GenericRelation du modele Post vers le modèle UpVote

@vincentporte vincentporte added the python Pull requests that update Python code label Jul 18, 2023
@vincentporte vincentporte self-assigned this Jul 18, 2023
@vincentporte vincentporte changed the title [UPVOTE] sauvegarder les pages de documentation [UPVOTE] convertir la clé étrangère Post en clé étrangère générique Jul 20, 2023
@vincentporte vincentporte force-pushed the 351-forum-upvote branch 2 times, most recently from 74bad72 to 031807a Compare July 20, 2023 16:13
@vincentporte vincentporte marked this pull request as ready for review July 20, 2023 16:15
Copy link
Contributor

@francoisfreitag francoisfreitag left a 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)
Copy link
Contributor

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.

verbose_name="Post",
)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincentporte
Copy link
Contributor Author

merci @francoisfreitag !

@vincentporte vincentporte force-pushed the 351-forum-upvote branch 2 times, most recently from 0275e3d to 838986f Compare July 25, 2023 08:49
@vincentporte vincentporte merged commit 7a49fa8 into master Jul 25, 2023
4 checks passed
@vincentporte vincentporte deleted the 351-forum-upvote branch July 25, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code
Projects
None yet
2 participants