librelist archives

« back to archive

does flask-admin work with one-to-one relationships?

does flask-admin work with one-to-one relationships?

From:
Ricardo Filipe Soares Garcia da
Date:
2014-02-26 @ 16:55
Hi list

I have the following models (edited with only the relevant bits):

# models.py

class Order(db.Model):
    id = db.Column(db.Integer, db.Sequence('order_id_seq'),
primary_key=True)

class DeliveryInformation(db.Model):
    id = db.Column(db.Integer, db.Sequence('delivery_information_id_seq'),
primary_key=True)
    order_id = db.Column(db.Integer, db.ForeignKey('order.id'),
nullable=False)
    order = db.relationship('Order',
backref=db.backref('delivery_information',
                            lazy='joined', uselist=False))

# admin.py

class OrderView(ModelView):
    column_display_pk = True

class DeliveryInformationView(ModelView):
    column_display_pk = True

admin = Admin(app, name='myapp')

admin.add_view(OrderView(models.Order, db.session))
admin.add_view(DeliveryInformationView(models.DeliveryInformation,
db.session))


I am creating a one-to-one relationship between Order and
DeliveryInformation. I'd like to use flask-admin to monitor these objects,
but I'm being faced with two issues:

- when consulting the view for Order, flask-admin shows me a MANDATORY
'delivery_information' field. I want this field to be optional. My logic is
that not all orders should have some delivery_information, but every
delivery_information must belong to an order.

- after saving some records for order and delivery_information, whenever I
try to access some order's edit page again I get the folowing error:

TypeError: argument of type 'DeliveryOption' is not iterable

It seems to me that flask-admin is trying to do some iteration on the
delivery_option, ignoring that the relationship is actually a one-to-one
and not a one-to-many (in which case it would return a list to iterate)

So, can I display one-to-one relationships with flask-admin?



-- 
___________________________ ___ __
Ricardo Garcia Silva

Re: [flask] does flask-admin work with one-to-one relationships?

From:
Andrea D'Amore
Date:
2014-02-28 @ 14:23
On Wed, Feb 26, 2014 at 5:55 PM, Ricardo Filipe Soares Garcia da
<ricardo.garcia.silva@gmail.com> wrote:

> It seems to me that flask-admin is trying to do some iteration on the
> delivery_option, ignoring that the relationship is actually a one-to-one and
> not a one-to-many (in which case it would return a list to iterate)
>
> So, can I display one-to-one relationships with flask-admin?

Check [1] and try to pull from tip rather than a release, I solved my
similar issue that way.


[1] https://github.com/mrjoes/flask-admin/issues/376

-- 
Andrea