python


Django FilePathField filter used entries


I have the following Model where the FilePathField should be unique:
class Gallery(models.Model):
template = models.FilePathField(path=".../templates/galleries/", unique=True)
In the admin, I would like the dropdown list to only show me those entries that have not been used, yet, in order to make the selection among available answers more easy. After all, any already used option in the resulting dropdown list will give me an error anyway and does not need to be shown to me in the admin. Unfortunately I am having problems wrapping my head around this. Can anyone tell me where I could insert something similar to the following:
used = [gallery.template for gallery in Gallery.objects.all()]
return [file for file in files if file not in used]
...or might I have overseen an option somewhere in Django that could already give me the desired result?

Related Links

How to listen for an AUDIO file using Python and Selenium Webdriver
Storing Encrypted Data On A MySQL Database with Python, Pandas and SQLAlchemy [Connection Lost]
How to make python decorators work like a tag to make function calls “by tag”
Pandas - Remove index column
Setting SublimeRepl to work inside venv (sublime 3)
python-docx get info from dropdownlist (in table)
Creating audio file with gTTS for Google Speech API [duplicate]
Python: Make raw input remember commands [duplicate]
Can Omnicomplete in Vim for python/3 complete function names or just methods?
Slowness on iterating over namedtuple and dicts for defined pairs
I'm trying to put these inputs into a text file, [duplicate]
Printing Dictionaries? [closed]
OpenCV's frame count always printing 0
Including first and last elements in list comprehension
how to see output history on pycharm?
plotting just a single rgb color in matplotlib

Categories

HOME
python
ssas-2012
blockchain
mapping
puppet
google-sheets-api
laravel-5.2
sbt-assembly
flyway
quill
devstack
bro
triggers
proguard
desktop
netflix-feign
slim-3
metronic
wysiwyg
public-key-encryption
cross-platform
phpbb
redux-observable
google-openid
tree-traversal
styles
osmdroid
ui5
emv
classpath
dd-wrt
roundcube
protobuf-net
android-vpn-service
backup-strategies
stocks
canvasjs
swiftcharts
data-extraction
ios-ui-automation
oscommerce
liquid-xml
zero
codesys
dart-pub
nashorn
spring-bean
scalafx
filepath
gauss
gist
seamless-immutable
spell-checking
rhel6
dwarf
decompress
collapsingtoolbarlayout
visual-studio-templates
qos
chessboard.js
firepath
uiprogressview
freetype2
instruments
jackson-databind
soda
gradle-eclipse
asp.net-mvc-partialview
usb-drive
anti-cheat
group-concat
spservices
hateoas
unity5.3
ffprobe
git-checkout
adodb
ticket-system
android-search
tilestache
activity-streams
mser
and-operator
node-inspector
em
sortable
csplit
cppdepend
sgml
lumx
flash-cc
convex-polygon
facebook-sdk-3.1
vertical-rhythm
ruboto
cgimageref
resgen
fluidsynth
vt100
snapjs
mozart-mvc
ubuntu-11.10
static-variables
makefile-project
authenticode
pivotal-crm
delegatecommand
rtsp-client
economics
divx

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App