On Jan 22, 2:15 pm, Igor <[email protected]> wrote:
> Hello,
>
> I need to exclude some items from a QuerySet based on field analysis
> with regular expressions. Which means in my understanding means that I
> need to first evaluate the QuerySet and then go thru it and use python
> to remove some items based on my analysis.
>
> Now, how can I accomplish that? I was not able to find a way to remove
> items from a QuerySet.
>
> Thanks in advance
>
> Igor
If it's a simple regex comparison on a field, you may be able to do it
directly in the query:
qs = MyModel.objects.exclude(fieldname__regex=r'^regex')
If you really do need to iterate through and exclude things, a
queryset acts just like a list so you can .pop() items and del() them.
Or better, you can append the items you *do* want to a separate list.
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.