django-cms/djangocms-link

Not possible to use AbstractLink as associated link in own CMSPlugin

jedie opened this issue · 3 comments

jedie commented

I would like to do something like this:

from django.db import models
from cms.models.pluginmodel import CMSPlugin

from djangocms_link.models import AbstractLink


class FooPluginModel(CMSPlugin):
    title = models.CharField(max_length=50)

class AssociatedLink(AbstractLink):
    plugin = models.ForeignKey(FooPluginModel, related_name="links")

This doesn't work and raise into a error like this:

ValueError: 'AssociatedLink' has more than one ForeignKey to 'FooPluginModel'.

This raised in django.forms.models._get_foreign_key() with local variables like:

fks_to_parent=[
    <django.db.models.fields.related.ForeignKey: parent>,
    <django.db.models.fields.related.OneToOneField: cmsplugin_ptr>
]

The problem is IMHO that djangocms_link.models.AbstractLink inherit from CMSPlugin

Any idea how to handle this?

Think there should be a Base-Link-class that inherit only from models.Model ?!?

jedie commented

Hm. #136 will really fix this issues ?!?

@jedie
I don't see a use-case for creating another abstract class. We don't want to support "generic link objects". The idea behind the abstract class is to support other fields for the link plugin.
In general is not a good idea to create a model with a direct fk to a plugin, considering the draft/live states.

jedie commented

I don't see a use-case for creating another abstract class.

The use-case is the example from above:

One CMSPlugin with a flexible count of links as admin inlines.

I didn't see a other way to implement this. Because of the ValueError: 'FooLinkModel' has more than one ForeignKey to 'BarPluginModel'.

Any Idea?