Let the models class:
class MyModel(models.Model):
name = models.CharField(max_length=200)
category = models.CharField(max_length=200)
I want to get all the objects of MyModel
except those with a specific category. I'm using this code:
[mm for mm in MyModel.objects.all() if mm.category != u'mycategory']
Is there another solution for this question?
Take a look at this documentation: https://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-objects-with-filters , you want to use an exclude filter.
So somethig like:
objects = MyModel.objects.exclude(category= u'mycategory')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With