django-filter

Using 'django-filter' with CHOICES field - need "Any" option.

I'm using the very cool django-filter (via: http://github.com/alex/django-filter) and either can't seem to wrap my head around the docs, or maybe just need a little boost. When I show the filter form on an object list page, for a FK field I get the drop down that includes a "-----" which results in an "any" type filter. But I have some ...

custom django template filters grouped as classes?

As far as I have understood, a django filter is just a python function which could be used in a html page. I need to do some thing like this - I need to group functions / django filters as python classes. For example, if I have a filter to do list operation like: {{ my_list|index:3 }} which will return the 3rd item of my_list. I have a...

How to preserve filter selection after save in Django Admin

First, I did look at this question, but its over a year old. Surely now there is a good way in Django 1.1.1 to carry filter selection forward after a user clicks the save button in the Admin. In a table with thousands of records, filtering is essential. And if a user makes several filter choices that effort shouldn't have to be repeat...

Ignoring case with __startswith

I'm trying to filter an object based off its first letter with: topics = SpecialtyCategory.objects.filter(name__startswith=request.GET.get('filter')) The problem is that the name could be "Example" or "example" and I want to get all SpecialtyCategory regardless of the case. How do I do this? ...

Django filters - Using an AllValuesFilter (with a LinkWidget) on a ManyToManyField

This is my first Stack Overflow question, so please let me know if I do anything wrong. I wish to create an AllValues filter on a ManyToMany field using the wonderful django-filters application. Basically, I want to create a filter that looks like it does in the Admin, so I also want to use the LinkWidget too. Unfortunately, I get an...

Hide filter items that produce zero results in django-filter

I have an issue with the django-filter application: how to hide the items that will produce zero results. I think that there is a simple method to do this, but idk how. I'm using the LinkWidget on a ModelChoiceFilter, like this: provider = django_filters.ModelChoiceFilter(queryset=Provider.objects.all(), widget=django_filters.widg...

Django queryset returning nothing but []

I've been able to do this through the django environment shell, but hasn't worked on my actual site. Here is my model: class ShoeReview(models.Model): def __unicode__(self): return self.title title = models.CharField(max_length=200) slug = models.SlugField(unique=True) keywords = models.Te...

FieldError when annotating over foreign keys

I have a models file that looks similar to the following: class WithDate(models.Model): addedDate = models.DateTimeField(auto_now_add=True) modifiedDate = models.DateTimeField(auto_now=True) class Meta: abstract = True class Match(WithDate): ... class MatchFilter(django_filters.FilterSet): class Meta: ...

How to filter Many2Many / Generic Relations properly with Q?

Hi, I have 3 Models, the TaggedObject has a GenericRelation with the ObjectTagBridge. And the ObjectTagBridge has a ForeignKey to the Tag Model. class TaggedObject(models.Model): """ class that represent a tagged object """ tags = generic.GenericRelation('ObjectTagBridge', blank=Tr...

Date filter: wrong format

I have this field in my Post model: created = models.DateTimeField(_('created'), default=datetime.now) In my template I have this: {{ post.created|date:"SHORT_DATE_FORMAT" }} I my settings.py I have this: LANGUAGE_CODE = 'it' USE_L10N = True But I get this: th03-0500RCDT_marAMCDTE_maggio-0500RMagAMCDT Why ? This is the docum...

Unescaping HTML in Django

I have html encoded text which reads like this: RT <a href="http://twitter.com/freuter"&gt;@freuter&lt;/a&gt;... I want this displayed as html but I am not sure if there is a filter which i can apply to this text to convert the html-encoded text back to html ... can someone help? ...

Django Nested Filter Values

This line works and returns the value that I'm looking for: logs = Log.objects.filter(filterURI=aFilter.uri).values()[0]['yk'] However, when I try to add another filter and do the same I get errors: logs = Log.objects.filter(filterURI=aFilter.uri).filter(k=k-1).values()[0]['yk'] My understanding is that a object.filter returns a qu...

chain filter and exclude on django model with field lookups that span relationships

I have the following models: class Order_type(models.Model): description = models.CharField() class Order(models.Model): type= models.ForeignKey(Order_type) order_date = models.DateField(default=datetime.date.today) status = models.CharField() processed_time= models.TimeField() I want a list of the order types tha...

Django "evaluate" filter?

I've got a view func like this: def user_agreement(request): return response(request, template='misc/flatpage.html', vars={'fp':FlatPage.objects.get(key='user-agreement')}) And then the template looks like this: <h2>{% block title %}{{ fp.title }}{% endblock %}</h2> {{ fp.content|markdown }} This works pretty well,...

How do I translate the output of a filter in Django

I have some template code that looks like: <input type='submit' value='{{ need.satisfied|yesno:"Resend this document now,Send this document now" }}' /> I'd like to be able to translate it but that appears to be difficult to accomplish. http://code.djangoproject.com/ticket/3804 mentions {{ _("Some String") }} which appears to work...

Is it possible to pass SafeData instances to Django templates?

I know that it's possible to have a template filter return a SafeData instance by doing something similar to the following. from fictitious import guaranteed_safe from django.utils.safestring import mark_safe def myfilter(text): return mark_safe(guaranteed_safe(text)) My question is whether it's possible to "mark as safe" variab...

Django select distinct

models.py class Category(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Gender(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Post(models.Model): name = models.CharField(max_length=50) cat...