Commit a903bc0a by Alex Gaynor

Update to work with django 1.2

parent d71c3069
from collections import defaultdict from collections import defaultdict
import django
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.db.models.fields.related import ManyToManyRel from django.db.models.fields.related import ManyToManyRel
...@@ -49,7 +50,7 @@ class TaggableManager(object): ...@@ -49,7 +50,7 @@ class TaggableManager(object):
def save_form_data(self, instance, value): def save_form_data(self, instance, value):
getattr(instance, self.name).set(*value) getattr(instance, self.name).set(*value)
def get_db_prep_lookup(self, lookup_type, value): def get_prep_lookup(self, lookup_type, value):
if lookup_type != "in": if lookup_type != "in":
raise ValueError("You can't do lookups other than \"in\" on Tags") raise ValueError("You can't do lookups other than \"in\" on Tags")
if all(isinstance(v, Tag) for v in value): if all(isinstance(v, Tag) for v in value):
...@@ -66,6 +67,9 @@ class TaggableManager(object): ...@@ -66,6 +67,9 @@ class TaggableManager(object):
sql, params = qs.values_list("pk", flat=True).query.as_sql() sql, params = qs.values_list("pk", flat=True).query.as_sql()
return QueryWrapper(("(%s)" % sql), params) return QueryWrapper(("(%s)" % sql), params)
if django.VERSION < (1, 2):
get_db_prep_lookup = get_prep_lookup
def formfield(self, form_class=TagField, **kwargs): def formfield(self, form_class=TagField, **kwargs):
defaults = { defaults = {
"label": "Tags", "label": "Tags",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment