bpepple / metron

Django website for a comic book database
https://metron.cloud/
GNU General Public License v3.0
61 stars 7 forks source link

Add support for other external services #227

Open Buried-In-Code opened 5 months ago

Buried-In-Code commented 5 months ago

Describe the solution you'd like Metron has support for Comicvine Ids, it would be nice if this could be expanded to include other services such as Marvel, GCD, League of Comics, etc...

Describe alternatives you've considered Currently I have to manually search in each service using title, year and number

Additional context

bpepple commented 5 months ago

This is something I've thought about adding since I would just need to add a AlternativeSources model like:

from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models

class AlternativeSources(models.Model):
    class Source(models.TextChoices):
        COMICVINE = "C", "Comic Vine"
        GCD = "G", "Grand Comics Database"
        LOCG = "L", "League of Comic Geeks"
        MARVEL = "M", "Marvel"

    source = models.CharField(max_length=1, choices=Source.choices, default=Source.COMICVINE)
    id_ = models.PositiveIntegerField("ID")

    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey("content_type", "object_id")

    class Meta:
        indexes = [models.Index(fields=["content_type", "object_id"], name="ct_obj_id_idx")]
        ordering = ["content_type", "object_id"]

    def __str__(self) -> str:
        return f"{self.source}: {self.id_}"

I'd also need to write some data migrations for existing CV_ID's, but that won't be terribly hard.

The only thing stopping me from implementing this is finding a solution to add a Post method for a model with a Generic Relation to the API, otherwise I couldn't automate adding this information.

bpepple commented 5 months ago

Did a little searching on this and the only project I could find was this (which was archived yesterday) :

https://github.com/LilyFoote/rest-framework-generic-relations