i have odoo17 project and fastapi for api and i have  problems with processing media files(photo,video) follow best practices and fix it: @router.get("/{application_id}", response_model=ApplicationDetail)
async def get_application_detail(
        application_id: int,
        env: Annotated[Environment, Depends(odoo_env)],
        partner: Annotated[Partner, Depends(get_partner_with_session)],
):
    Application = env['mahallam.application'].sudo()
    application = Application.browse(application_id)

    if not application.exists():
        raise HTTPException(status_code=404, detail=_("Application not found"))

    return ApplicationDetail(
        id=application.id,
        status=application.status,
        description=application.description,
        date=application.created_at,
        category=application.category_id.name if application.category_id else None,
        subcategory=application.subcategory_id.name if application.subcategory_id else None,
        state=[(state.name, state.description) for state in application.state_id],
        images=[get_media_url(media._name, media.id, 'media') for media in application.image_ids],
        after_images=[get_media_url(media._name, media.id, 'media') for media in application.after_image_ids],
        is_author=application.partner_id.id == partner.id
    )


@router.post("/create", response_model=ApplicationDetail)
async def create_application(
        env: Annotated[Environment, Depends(odoo_env)],
        partner: Annotated[Partner, Depends(get_partner_with_session)],
        category_id: int = Form(...),
        subcategory_id: int = Form(...),
        description: str = Form(...),
        latitude: float = Form(...),
        longitude: float = Form(...),
        media_files: List[UploadFile] = File(...),
):
    Application = env['mahallam.application'].sudo()
    ApplicationMedia = env['mahallam.application.media'].sudo()

    main_home = partner.home_ids.filtered(lambda h: h.is_main_home)

    application_vals = {
        'category_id': category_id,
        'subcategory_id': subcategory_id,
        'description': description,
        'latitude': latitude,
        'longitude': longitude,
        'status': 'created',
        'partner_id': partner.id,
    }
    if main_home:
        application_vals.update({
            'mahalla_id': main_home.home_id.mahalla_id.id,
            'district_id': main_home.home_id.district_id.id,
            'region_id': main_home.home_id.region_id.id,
        })

    application = Application.create(application_vals)

    for media_file in media_files:
        content = await media_file.read()
        ApplicationMedia.create({
            'application_id': application.id,
            'media': content,
            'media_name': media_file.filename
        })

    return await get_application_detail(application.id, env, partner)from odoo import models, fields, api, _
import datetime


class Application(models.Model):
    _name = 'mahallam.application'
    _description = 'Application'

    name = fields.Char(string=_('Nomi'))
    partner_id = fields.Many2one('res.partner', string=_('Partner'), required=True, default=lambda self: self.env.user.partner_id)
    category_id = fields.Many2one('mahallam.application.category', string=_('Category'))
    subcategory_id = fields.Many2one('mahallam.application.subcategory', string=_('Subcategory'))
    description = fields.Text(string=_('Description'), required=True)
    image_ids = fields.One2many('mahallam.application.media', 'application_id', string=_('Images'), attachment=True)
    after_image_ids = fields.One2many('mahallam.application.after.media', 'application_id', string=_('After Images'), attachment=True)
    count_media = fields.Integer(string=_('Count Media'), compute='_compute_count_media')
    status = fields.Selection(
        [
            ('created', _('Created')),
            ('completed', _('Completed')),
            ('in_progress', _('In Progress')),
            ('rejected', _('Rejected')),
            ('cancelled', _('Cancelled')),
        ],
        default="created"
    )
    state_id = fields.One2many('mahallam.application.state', 'application_id', string=_('Status'))
    mahalla_id = fields.Many2one(
        'mahalla', string=_('Home Mahalla'), store=True, readonly=True
    )
    district_id = fields.Many2one(
        'district', string=_('Home District'), store=True, readonly=True
    )
    region_id = fields.Many2one(
        'region', string=_('Home Region'), store=True, readonly=True
    )
    created_at = fields.Datetime(string=_('Created At'), default=datetime.datetime.now())
    latitude = fields.Float(string=_('Latitude'))
    longitude = fields.Float(string=_('Latitude'))


    @api.model
    def write(self, vals):
        partner = self.env.user.partner_id
        main_home = partner.home_ids.filtered(lambda h: h.is_main_home)
        if main_home:
            vals.update({
                'mahalla_id': main_home.home_id.mahalla_id.id,
                'district_id': main_home.home_id.district_id.id,
                'region_id': main_home.home_id.region_id.id,
            })
        return super().write(vals)

    def write(self, vals):
        res = super().write(vals)
        if 'status' in vals:
            self.env['mobile.app.push.notification'].create({
                'name': 'Application Status Update',
                'body': f'Your application #{self.id} status changed to {vals["status"]}',
                'notification_type': 'application_status',
                'model_name': 'mahallam.application',
                'object_id': self.id,
                'send_notification_to': 'to_partner',
                'partner_ids': [(6, 0, [self.create_uid.partner_id.id])]
            })
        return res

    def _compute_count_media(self):
        for application in self:
            application.count_media = len(application.image_ids)


class ApplicationMedia(models.Model):
    _name = 'mahallam.application.media'
    _description = 'Application Media'

    application_id = fields.Many2one('mahallam.application', string='Application', required=True, ondelete='cascade')
    media = fields.Binary(string=_('Media'))
    media_name = fields.Char(string=_('Name'))
class ApplicationAfterMedia(models.Model):
    _name = 'mahallam.application.after.media'
    _description = 'Application Media'

    application_id = fields.Many2one('mahallam.application', string='Application', required=True, ondelete='cascade')
    media = fields.Binary(string=_('Media'))
    media_name = fields.Char(string=_('Name'))


class ApplicationCategory(models.Model):
    _name = 'mahallam.application.category'
    _description = 'Application Categories'

    name = fields.Char(string=_('Nomi'))


class ApplicationSubcategory(models.Model):
    _name = 'mahallam.application.subcategory'
    _description = 'Application Subcategories'
    
    name = fields.Char(string=_('Nomi'))
    category_id = fields.Many2one('mahallam.application.category', string=_('Category'))


class ApplicationState(models.Model):
    _name = 'mahallam.application.state'
    _description = 'Application States'

    name = fields.Selection(
        [
            ('created', _('Application Created')),
            ('application_sent', _('Application Sent')),
            ('started_work', _('Department Started Work')),
            ('ended_work', _('Department Ended Work')),
            ('message_sent', _('Message Sent')),
            ('was_addressed', _('Was Addressed')),
        ],
        default="created"
    )
    description = fields.Char(string=_('Description'))
    application_id = fields.Many2one('mahallam.application', string=_('Application'))

from pydantic import BaseModel
from typing import Optional, List, Tuple
from datetime import datetime
from odoo.addons.fastapi_addon.schemas.base_schema import PagedCollection


class ApplicationBase(BaseModel):
    id: int
    status: str
    description: str
    date: datetime
    category: Optional[str]
    subcategory: Optional[str]


class ApplicationList(ApplicationBase):
    photo: Optional[str]
    is_author: bool


class ApplicationDetail(ApplicationBase):
    state: List[Tuple[str, str]]
    images: List[str]
    after_images: List[str]


class ApplicationCreate(BaseModel):
    category_id: int
    subcategory_id: int
    description: str
    latitude: float
    longitude: float


class UserApplicationsList(BaseModel):
    applications: PagedCollection[ApplicationList]
    total_count: int


class ApplicationCategoryBase(BaseModel):
    id: int
    name: str


class ApplicationSubcategoryBase(BaseModel):
    id: int
    name: str


class ApplicationCategoryWithSubcategories(BaseModel):
    id: int
    name: str
    subcategories: List[ApplicationSubcategoryBase]
from ..settings import STAGE
import random
import string


def unique_str_generator(length=15):
    characters = string.ascii_letters + string.digits
    random_string = "".join(random.choice(characters) for _ in range(length))
    return random_string

def get_media_url(model: str, object_id: int, field_name: str):
    if STAGE == "production":
        base_url = "https://mahallam-backend.uicgroup.tech"
    else:
        base_url = "http://localhost:8070"
    return f"{base_url}/web/image/{model}/{object_id}/{field_name}/?{unique_str_generator(10)}"