Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我当前的代码如下:
suggestions = Photo.objects.extra(where=['id!=%s'], params=[p.id]).order_by('?')[:10]
我想知道是否有更好的解决方案。
看起来你可以只使用一个基本的exclude:
exclude
suggestions = Photo.objects.exclude(id=p.id).order_by('?')[:10]