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

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

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