21 lines
670 B
Python
21 lines
670 B
Python
import random
|
|
from typing import Optional
|
|
from sqlalchemy.orm import Session
|
|
from models.framework import Framework
|
|
from schemas.framework import FrameworkSchema
|
|
|
|
def get_random_framework(db: Session) -> Optional[FrameworkSchema]:
|
|
"""
|
|
Retrieves a random framework from the database.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
|
|
Returns:
|
|
Optional[FrameworkSchema]: The randomly selected framework schema object, or None if no frameworks exist.
|
|
"""
|
|
frameworks = db.query(Framework).all()
|
|
if not frameworks:
|
|
return None
|
|
random_framework = random.choice(frameworks)
|
|
return FrameworkSchema.from_orm(random_framework) |