django - Adding a dict if the query set is empty -


i need check if django query has values if not need append dict query set validation purpose. so, don't want create entry in database.

obviously, since can't append queryset(attribute error) there other way add this?

listing = listing.objects.values() if len(listing) < 1:     listing.append({         'address': 'some string',         'range': 'some other string'     }) 

if want manually create list when queryset empty, that's rather easy

listing = listing.objects.values() if len(listing) < 1:     listing = [{         'address': 'some string',         'range': 'some other string'     }] 

if want append regardless of whether queryset empty or not:

listing = list(listing.objects.values()) listing.append({         'address': 'some string',         'range': 'some other string'     }) 

Comments

Popular posts from this blog

sql - MySQL - Finding Empty relations -

javascript - Why jQuery Select box change event is now working? -

c - Android and JNI real time clock -