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

How to do inline editing for manytomany relations? #1734

Open
scythargon opened this issue Oct 17, 2018 · 1 comment
Open

How to do inline editing for manytomany relations? #1734

scythargon opened this issue Oct 17, 2018 · 1 comment

Comments

@scythargon
Copy link

scythargon commented Oct 17, 2018

Hi!
I have two models

class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    message_text = db.Column(db.Text, nullable=True)
    stickers = db.relationship('StickerMessageAssociation', back_populates='message')
    ...

and 

class Sticker(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    file_id = db.Column(db.String(255), nullable=False)
    messages = db.relationship('StickerMessageAssociation', back_populates='sticker')
   ...

and an intermediate model to connect these two:

class StickerMessageAssociation(db.Model):
    __tablename__ = 'message_to_sticker'

    message_id = db.Column(db.Integer, db.ForeignKey('message.id'), primary_key=True)
    sticker_id = db.Column(db.Integer, db.ForeignKey('sticker.id'), primary_key=True)

    message = db.relationship('Message', back_populates='stickers')
    sticker = db.relationship('Sticker', back_populates='messages')

The problem arises when I try to enable support for assigning stickers to the messages in the flask-admin via inline model editing:

class InlineStickerModelForm(InlineFormAdmin):
    form_label = 'Stickers'

    def __init__(self):
        return super(InlineStickerModelForm, self).__init__(StickerMessageAssociation)


class MessageView(ModelView):
    ...
    inline_models = (..., InlineStickerModelForm())

When I add a sticker to a message in the admin panel, which looks like this:
image

and try to save the page, I get the following error:
image

Tried to hack my way around scaffold_inline_form_models and in a few other directions but no luck so far. Any suggestions would be very much appreciated. Thank you!

@scythargon scythargon changed the title Support for manytomany inline models How to do inline editing for manytomany relations? Oct 17, 2018
@git-bone
Copy link

git-bone commented Dec 7, 2018

similar issue to #1472 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants