B
B
B1ackGh0st2020-08-26 06:18:02
PostgreSQL
B1ackGh0st, 2020-08-26 06:18:02

How to display unlinked entries in the dropdown list?

Guys help!
1. How can I make sure that when you add or edit an employee in flask-admin, only those emails that are not linked to other employees are in the drop-down list?
2. As in the admin panel in the email model, when creating and editing, not the employee ID was specified, but his full name

class Subscriber(db.Model):
    __tablename__ = 'subscriber'
    name = db.Column(db.String(255), index=True)  # Имя

   # Савязь с эл.почтой
    email = db.relationship('Email', backref=db.backref('subscriber_email', lazy=True), lazy=True,
                            foreign_keys="Email.subscriber")

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return self.name

    def __str__(self):
        return self.name

    def __init__(self, name=None):
        self.number = name


''' email '''
class Email(db.Model):
    __tablename__ = 'email'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), index=True)  # E-mail
    subscriber = db.Column(db.Integer, db.ForeignKey('subscriber.id'))  # Связь с абонентом

    def __unicode__(self):
        return self.email

    def __repr__(self):
        return self.email

    def __init__(self, email):
        self.email=email

''' Таблица: сотр- эл.почта '''
subscriber_email = db.Table(
    'subscriber_email',
    db.Column('subscriber_id', db.Integer(), db.ForeignKey('subscriber.id')),
    db.Column('email_id', db.Integer(), db.ForeignKey('email.id'))
)


Thanks a lot!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question