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 to filter objects by a specific choice

I have model like this:

class ScientificInfo(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    is_approved = models.CharField(max_length=64, choices=(('0', 'yes'), ('1', 'no')), blank=True)
    is_interviewed = models.BooleanField(default=False)

how can I filter this model by is_approved field which is a choicefield? I wrote this line but doesnt work

approved = ScientificInfo.objects.filter(is_approved__in='0').all()

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 :

Using the exact field lookup would probably make more sense here:

approved = ScientificInfo.objects.filter(is_approved__exact='0').all()

https://docs.djangoproject.com/en/4.0/ref/models/querysets/#exact

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