# How to find latest model publish file path

**URL:** <https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203>\
**Category:** Pipeline Integrations\
**Created:** [October 1, 2019, 9:45pm UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203 "2019-10-01T21:45:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkiser](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@jkiser](https://community.shotgridsoftware.com/u/jkiser)\
**Post date:** [October 1, 2019, 9:45pm UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203/1 "2019-10-01T21:45:00Z")

</div>

Can anyone help me with finding a way to return the publish path of an assets latest published model task in the shotgun api? I can see the path on my project website but can’t seem to get my filters to return the information I need.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [October 2, 2019, 8:37am UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203/2 "2019-10-02T08:37:51Z")

</div>

Maybe something like this would work for you?

```python
r = sg.find_one("PublishedFile",
                [["task.Task.id","is",13151],
                 ["name","is", "alt.ma"]],
                fields = ["path"],
                order = [{'field_name':'version_number', 'direction':'desc'}])

```

It’s sorting by version number and returning the first result. You could adjust the filters so that they are more suitable for you.  
If for example, you don’t know the id of the model task, but you do know the entity id you could do have:

```python
r = sg.find_one("PublishedFile",
                [["task.Task.content","is","Model"],
                 ["entity.Shot.id","is", 1381],
                 ["name","is", "alt.ma"]],
                fields = ["path"],
                order = [{'field_name':'version_number', 'direction':'desc'}])

```

---

<div class="post-metadata">

**Author:** ![jkiser](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@jkiser](https://community.shotgridsoftware.com/u/jkiser)\
**Post date:** [October 2, 2019, 4:17pm UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203/3 "2019-10-02T16:17:43Z")

</div>

Hey Philip thank you so much once again! That helped very much. Just for everyones knowledge here this is what I ended up using.

```python
filters = [
    ['entity.Asset.code', 'is', asset_name],
    ['project', 'is', {'type': 'Project', 'id': project_id}],
    ['task.Task.content', 'is', 'model']
]
fields = ['path']
order = [{'field_name': 'version_number', 'direction': 'desc'}]

path_dict = sg.find_one('PublishedFile', filters, fields, order)

```

---

<div class="post-metadata">

**Author:** ![dougm](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/dougm/32/434_2.png) [@dougm](https://community.shotgridsoftware.com/u/dougm)\
**Post date:** [November 6, 2019, 1:16am UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203/4 "2019-11-06T01:16:08Z")

</div>

Is there any way to do this in the UI?

ie. just one result, after sorting

This is similar to the “latest”-checkbox for Version entities, but we need it for something else.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [November 6, 2019, 9:46am UTC](https://community.shotgridsoftware.com/t/how-to-find-latest-model-publish-file-path/3203/5 "2019-11-06T09:46:33Z")

</div>

You could create a query field on the entity or task showing only the latest published file, something like this:

 ![Assets___My_Project](https://global.discourse-cdn.com/shotgunsoftware/original/2X/2/25e25c2ef1d8dd7bb7eaef3bc0dd763c3565a3ab.png)

But I don’t think you could create a page with it filtered to just the latest.
