Add Pixel.restaurants property

- the property loads all `Restaurant`s from the database that
  are within the `Pixel`
This commit is contained in:
Alexander Hess 2021-01-31 19:20:17 +01:00
commit 63e8e94145
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
3 changed files with 58 additions and 2 deletions

View file

@ -2,6 +2,8 @@
from __future__ import annotations
from typing import List
import folium
import sqlalchemy as sa
import utm
@ -111,6 +113,22 @@ class Pixel(meta.Base):
return self._southwest
@property
def restaurants(self) -> List[db.Restaurant]: # pragma: no cover
"""Obtain all `Restaurant`s in `self`."""
if not hasattr(self, '_restaurants'): # noqa:WPS421 note:d334120e
self._restaurants = ( # noqa:ECE001
db.session.query(db.Restaurant)
.join(
db.AddressPixelAssociation,
db.Restaurant.address_id == db.AddressPixelAssociation.address_id,
)
.filter(db.AddressPixelAssociation.pixel_id == self.id)
.all()
)
return self._restaurants
def clear_map(self) -> Pixel: # pragma: no cover
"""Shortcut to the `.city.clear_map()` method.