Skip to content

Commit

Permalink
Revert "First stab at per-object questions. It still needs a bit more…
Browse files Browse the repository at this point in the history
… work."

This reverts commit 786283f.

Whoops, wrong branch :)
  • Loading branch information
brosner committed Oct 29, 2008
1 parent 786283f commit 41d5200
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 96 deletions.
30 changes: 4 additions & 26 deletions faq/admin.py
@@ -1,33 +1,11 @@

from datetime import datetime

from django.contrib import admin
from django.contrib.contenttypes import generic

from faq.models import Question, QuestionAssociation

class QuestionGenericInline(generic.GenericStackedInline):
model = Question
ct_fk_field = "object_pk"
fields = ("sort_order", "text", "answer", "status")
extra = 2

class QuestionAssociationGenericInline(generic.GenericTabularInline):
model = QuestionAssociation
ct_fk_field = "object_pk"
raw_id_fields = ("question",)
from faq.models import Question
from datetime import datetime


class QuestionAdmin(admin.ModelAdmin):

list_display = ['text', 'sort_order', 'created_by', 'created_on', 'updated_by', 'updated_on', 'status']
fieldsets = (
(None, {
"fields": ("slug", "text", "answer", "status", "sort_order"),
}),

("Object Association", {
"fields": ("content_type", "object_pk"),
}),
)

def save_model(self, request, obj, form, change):
'''
Expand Down
21 changes: 7 additions & 14 deletions faq/managers.py
@@ -1,12 +1,9 @@

import datetime

from django.db import models
from django.db.models.query import QuerySet
from django.contrib.contenttypes.models import ContentType

import datetime
import faq.enums as enums


class QuestionQuerySet(QuerySet):
"""
A basic ''QuerySet'' subclass, provides query functionality and some helper methods for an intuitive interface.
Expand All @@ -32,16 +29,12 @@ class QuestionManager(models.Manager):
to helpful utility methods.
"""

def get_query_set(self):
return QuestionQuerySet(self.model)

def active(self, slug=None):
return self.get_query_set().active(slug=slug)

def get_for_object(self, obj):
"""
Creates a queryset matching all questions for the given object.
"""
ct = ContentType.objects.get_for_model(obj)
return self.filter(content_type=ct, object_pk=obj.pk)



18 changes: 1 addition & 17 deletions faq/models.py
Expand Up @@ -2,9 +2,6 @@
from datetime import datetime
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType

from faq.managers import QuestionManager
import faq.enums as enums

Expand Down Expand Up @@ -33,11 +30,6 @@ class Question(FaqBase):
status = models.IntegerField( choices=enums.QUESTION_STATUS_CHOICES, default=enums.STATUS_INACTIVE, help_text="Only questions with their status set to 'Active' will be displayed. " )
sort_order = models.IntegerField(_('sort order'), default=0, help_text='The order you would like the question to be displayed.')

# an object specific question
content_type = models.ForeignKey(ContentType, null=True, blank=True)
object_pk = models.PositiveIntegerField(null=True, blank=True)
content_object = generic.GenericForeignKey(fk_field="object_pk")

objects = QuestionManager()

class Meta:
Expand All @@ -49,12 +41,4 @@ def __unicode__(self):
def save(self):
self.updated_on = datetime.now()
super(Question, self).save()

class QuestionAssociation(models.Model):
"""
A generic relation between a Question and some other object in the system.
"""
question = models.ForeignKey(Question)
content_type = models.ForeignKey(ContentType)
object_pk = models.PositiveIntegerField()
content_object = generic.GenericForeignKey(fk_field="object_pk")

Empty file removed faq/templatetags/__init__.py
Empty file.
39 changes: 0 additions & 39 deletions faq/templatetags/faq_tags.py

This file was deleted.

0 comments on commit 41d5200

Please sign in to comment.