mirror of
https://github.com/Hopiu/django-watson.git
synced 2026-03-16 22:00:22 +00:00
Update import of GenericForeignKey
This commit is contained in:
parent
20411df9e1
commit
9d6fc89516
1 changed files with 20 additions and 17 deletions
|
|
@ -6,7 +6,10 @@ import json
|
|||
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
try:
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
except ImportError:
|
||||
from django.contrib.contenttypes.generic import GenericForeignKey
|
||||
|
||||
def has_int_pk(model):
|
||||
"""Tests whether the given model has an integer primary key."""
|
||||
|
|
@ -19,54 +22,54 @@ def has_int_pk(model):
|
|||
isinstance(pk, models.ForeignKey) and has_int_pk(pk.rel.to)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
META_CACHE_KEY = "_meta_cache"
|
||||
|
||||
|
||||
class SearchEntry(models.Model):
|
||||
|
||||
"""An entry in the search index."""
|
||||
|
||||
|
||||
engine_slug = models.CharField(
|
||||
max_length = 200,
|
||||
db_index = True,
|
||||
default = "default",
|
||||
)
|
||||
|
||||
|
||||
content_type = models.ForeignKey(
|
||||
ContentType,
|
||||
)
|
||||
|
||||
object_id = models.TextField()
|
||||
|
||||
|
||||
object_id_int = models.IntegerField(
|
||||
blank = True,
|
||||
null = True,
|
||||
db_index = True,
|
||||
)
|
||||
|
||||
object = generic.GenericForeignKey()
|
||||
|
||||
|
||||
object = GenericForeignKey()
|
||||
|
||||
title = models.CharField(
|
||||
max_length = 1000,
|
||||
)
|
||||
|
||||
|
||||
description = models.TextField(
|
||||
blank = True,
|
||||
)
|
||||
|
||||
|
||||
content = models.TextField(
|
||||
blank = True,
|
||||
)
|
||||
|
||||
|
||||
url = models.CharField(
|
||||
max_length = 1000,
|
||||
blank = True,
|
||||
)
|
||||
|
||||
|
||||
meta_encoded = models.TextField()
|
||||
|
||||
|
||||
@property
|
||||
def meta(self):
|
||||
"""Returns the meta information stored with the search entry."""
|
||||
|
|
@ -77,14 +80,14 @@ class SearchEntry(models.Model):
|
|||
meta_value = json.loads(self.meta_encoded)
|
||||
setattr(self, META_CACHE_KEY, meta_value)
|
||||
return meta_value
|
||||
|
||||
|
||||
def get_absolute_url(self):
|
||||
"""Returns the URL of the referenced object."""
|
||||
return self.url
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
"""Returns a unicode representation."""
|
||||
return self.title
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "search entries"
|
||||
|
|
|
|||
Loading…
Reference in a new issue