python - Values of a dict in a dropdown django -
my models.py follows:
class sellermarketplaces(models.model): id = models.integerfield(db_column='id',primary_key=true) # field name made lowercase. seller_id = models.foreignkey('sellerdetails',db_column='seller_id') # field name made lowercase. mk_id = models.foreignkey('marketplace',db_column='mk_id') # field name made lowercase. username = models.charfield(db_column='username', max_length=100, blank=true, null=true)
i have following code in views
def marketplaces(request): seller = request.get.get('seller', '') allmarketplaces = sellermarketplaces.objects.filter(seller_id = seller).values('mk_id__marketplace') print allmarketplaces
through i'm getting following output:
[{'mk_id__marketplace': u'flipkart'}, {'mk_id__marketplace': u'snapdeal'}]
i want display values i.e., flipkart , snapdeal in dropdown i'm unable access values, when i'm writing
print allmarketplaces.values()
it's giving me
[{'username': u'mail@fields.com', u'seller_id_id': 1l, u'mk_id_id': 1l, 'id': 1l}, {'username': u'mail@fields.com', u'seller_id_id': 1l, u'mk_id_id': 2l, 'id': 2l}]
how can access values (flipkart & snapdeal)?
you're looking values_list
:
>>> allmarketplaces = sellermarketplaces.objects.filter(seller_id=seller).values_list('mk_id__marketplace', flat=true) >>> print allmarketplaces ['flipkart', 'snapdeal']
Comments
Post a Comment