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

elasticsearch python client - work with many nodes - how to work with sniffer -

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

Upload file with tags through OwnCloud or NextCloud API -