Comments (3)
Hi,
Can you be a bit more precies please? I don't understand what exactly you are trying to achieve.
from safrs.
Here is a Pseudocode example
- User (client API) supplies client_Id and client_secret and receives a token
- The user does a GET (using token) on TceContacts or TceContactsHst. The Get needs to have a filter something like this filter_by(User.client_id = token_user)
db.session.query(TceContacts).join(TceCampaign).join(User).filter_by(client_id = token_user).all()
- The user does a POST (using token) to TceContacts. The value in TceContacts.campId must exist in TceCampaign.id (foreign key constraint) filter_by(User.client_id = token_user)
db.session.query(TceContacts).join(TceCampaign).join(User).filter_by(client_id = token_user).all()
class Base(SAFRSBase, db.Model):
__abstract__ = True
id = db.Column(Integer, nullable=False, primary_key=True)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
modified_at = db.Column(db.DateTime,
default=db.func.current_timestamp(),
onupdate=db.func.current_timestamp())
active = db.Column(db.Boolean(), default=True)
class User(Base):
__tablename__ = 'user'
client_id = Column(String(100))
client_secret = Column(String(100))
firstName = Column(String(145))
lastName = Column(String(145))
address = Column(String(45))
tceCampaign = relationship("TceCampaign", back_populates="user")
class TceCampaign(Base):
__tablename__ = 'tceCampaign'
userId = Column(Integer, ForeignKey('user.id'))
name = Column(String(100))
dailyStartTime = Column(Time)
dailyEndTime = Column(Time)
startDays = Column(Integer)
user = relationship("User", back_populates="tceCampaign")
tceContacts = relationship("TceContacts", back_populates="tceCampaign", cascade="all,delete")
class TceContacts(Base):
__tablename__ = 'tceContacts'
http_methods = ["get", 'POST']
exclude_rels = ["tceCampRun"]
custom_decorators = [jwt_required, test_dec]
campId = Column(ForeignKey(u'tceCamp.id', ondelete=u'CASCADE'), index=True)
firstName = Column(String(145))
lastName = Column(String(145))
tceCampaign = relationship(u'TceCampaign', back_populates="tceContacts")
class TceContactsHst(Base):
__tablename__ = 'tceContactsHst'
http_methods = ["get"]
custom_decorators = [jwt_required, test_dec]
contactsId = Column(ForeignKey(u'tceContacts.id'), index=True)
runStatus = Column(String(45))
processId = Column(Integer)
process = Column(String(45))
rate = Column(Numeric(6, 4))
tceContacts = relationship(u'TceContacts')
from safrs.
Hi,
you can create a custom filter, e.g.:
class User(SAFRSBase, db.Model):
id = db.Column(String, primary_key=True)
username = db.Column(db.String(32))
@classmethod
def filter(cls, *args, **kwargs):
print(args, kwargs) # args[0] should contain the filter= url query parameter value
return cls.query.filter_by(username = args[0])
This filter will be called when you provide ?filter=user2
I hope this helps?
from safrs.
Related Issues (20)
- Invalid swagger for "properties" under "definitions" breaks defintions display and validation HOT 7
- Patch method unreliable? HOT 2
- Read-only Columns HOT 2
- Flask-SQLAlchemy weakref KeyError
- in version 3.0 _s_count function does not apply filters to query HOT 1
- `count` property value is wrong for `GET` methods HOT 1
- Unable to delete entries HOT 5
- overriding methods does not work HOT 2
- extend API with custom classes HOT 1
- requirements.txt too restrictive HOT 1
- Duplicate definitions generated HOT 5
- safrs doesn't work in python 3.9 - TypeError HOT 4
- expose_existing starts but no swagger.json found HOT 1
- Run in example demo_relationship.py creating users or books in flask_admin returns Integrity Errors HOT 17
- Doubts about SAFRS HOT 2
- JSONAPI relationship missing in the swagger documentation HOT 4
- Swagger generation removing plurals HOT 1
- Flask 2.0 / Flask-restful "ImportError: cannot import name '_endpoint_from_view_func'" HOT 1
- Possible issue with BIGINT primary keys? HOT 5
- Make many to many relationship methods extendable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from safrs.