Home > Software engineering >  How can I fetch one column with conditons in Django
How can I fetch one column with conditons in Django

Time:02-17

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.

CodePudding user response:

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/

  • Related