So I have one model, which uses a ContentType to point to a collections of
models across separate apps.

I want to be able to "plug in" the functionality linking that model to the
other models in the separate app. So we have the follwing:


class MyModelMixin(models.Model):
    """ Mixin to get the TheModel data into a MyModel
    ""
    updated_date = models.DateTimeField(null=True, blank=True)
    submission = GenericRelation(
        TheModel,
        related_query_name='the_related_name')
    class Meta:
        abstract = True



The main model model looks like this:

class TheModel(models.Model):
    """ This tracks a specific submission of an SAQ by a specific site
    """
    updated = models.DateTimeField()
    status = models.CharField(max_length=32, blank=True, null=True)
    final_score = models.DecimalField(
        decimal_places=2, max_digits=30, default=-1,
    )
    config = models.ForeignKey(Config, blank=True, null=True)
    content_type = models.ForeignKey(
        ContentType,
        blank=True,
        null=True)
    object_id = models.PositiveIntegerField(blank=True, null=True)
    my_model_instance = GenericForeignKey()

And the mixin is included in the MyModel models, which are available in
many different apps.

so I've jsut realised that the related name on the GenericRelation will
only work for one model (at least it appears to, and I've had issues with
that before with related name clashes, which this would be. How should I
get round this? Updating the related_name will require a migration, so is
theer a way to do this dynamically using the mixin, or should it be
hardcoded per app in which it's referenced.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANOQRbxcXAp6%3DdSbN1Zpeps1G%3DZVELWs5HYQGL_GH8YBTOQyCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to