Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I fetch one column with conditons in Django

id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
limit = models.PositiveIntegerField(default='255')
date = models.DateField()

Hello .

This is my model.I want to fetch the data for "limit" and "where id = 5" for example. How can I do that ? I want to use it as Integer. not Queryset.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If there is only one instance with id = 5 (it should be), then you can get value of limit using:

YourModel.objects.get(id=5).limit

You can read more about making queries here: https://docs.djangoproject.com/en/4.0/ref/models/querysets/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading