django command to fetch all columns of a table 1

django command to fetch all columns of a table

table = Country.objects.values_list('name_of_the_country', 'country_code')

Here is what the above code is Doing:
1. We are using the values_list() method to return a list of tuples.
2. The first element in each tuple is the name of the country.
3. The second element in each tuple is the country code.
4. We are using the country code as the key for the dictionary.
5. We are using the name of the country as the value for the dictionary.

Similar Posts