I can t get accurate value in dictionaries in django

0 votes

Whenever I try to print the dictionaries in Django I can't get what I need. The views models are given below. Geeks help to solve this beginner question

Views.py

def home(request):
    roomCate=dict(Room_Type.ROOM_CATEGORIES)
    roomUrl=Room_Type.objects.all()
    print(roomCate)
    print(roomUrl)

Whenever I print roomCate and roomUrl, I got what I need in roomUrl but, in roomCate I changing while printing the dictionaries of value, <QuerySet [<Room_Type: Sig>, <Room_Type: Lux>, <Room_Type: Elt>]> The value is not changing while print the value

But in {'Lux': 'Luxury', 'Sig': 'Signature', 'Elt': 'Elite'} the value is changing.

Here is my models.py

class Room_Type(models.Model):
    """Django data model Room_Type"""
    ROOM_CATEGORIES={
    ('Elt','Elite'),
    ('Lux','Luxury'),
    ('Sig','Signature')
    }

    image = models.ImageField(upload_to="pics")
    roomtype = models.CharField(choices=ROOM_CATEGORIES,max_length=20)
    price = models.CharField(blank=True, max_length=100)
    def __str__(self):
        return f'{self.roomtype}'

I want the method print result same as roomUrl but I can't get the value same as roomUrl. Please geeks help me solve this

Thank You

    return render(request,'index.html')
Dec 25, 2020 in Python by Mohamed
• 170 points
554 views

Hey, @Mohamed,

Are you facing any error while executing your code?  If you facing any code do post it here so that we can resolve this ASAP.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

+1 vote
1 answer

how do i get a optimal cutoff value(directly in the form of numeric) from roc curves?

The optimal CutOff value is the point ...READ MORE

answered Oct 17, 2019 in Python by Saira
3,373 views
0 votes
1 answer

How do I get user IP address in django?

Hii Kartik, check uwsgi + django source code and pass static param ...READ MORE

answered Apr 23, 2020 in Python by Niroj
• 82,840 points
9,185 views
0 votes
1 answer

How can I get all the request headers in Django?

Hello @kartik,  You can use request.headers to access the HTTP ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,840 points
13,227 views
0 votes
1 answer

How to get value from form field in django framework?

Hello @kartik, Using a form in a view can ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,840 points
9,168 views
0 votes
1 answer

How can I get the username of the logged-in user in Django?

Hello @kartik, You can use the request object ...READ MORE

answered Jul 29, 2020 in Python by Niroj
• 82,840 points
10,820 views
0 votes
1 answer

How can I get the absolute URL (with domain) in Django?

Hello @kartik, Use handy request.build_absolute_uri() method on request, pass it ...READ MORE

answered Aug 6, 2020 in Python by Niroj
• 82,840 points
10,384 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
2,504 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
1,580 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP