mirror of
https://github.com/haiwen/seahub.git
synced 2025-05-06 15:06:43 +00:00
13 lines
272 B
Python
13 lines
272 B
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
def get_first_object_or_none(queryset):
|
|
"""
|
|
A shortcut to obtain the first object of a queryset if it exists or None
|
|
otherwise.
|
|
"""
|
|
try:
|
|
return queryset[:1][0]
|
|
except IndexError:
|
|
return None
|