Hello Django Users,

This is my first time using the admin site of Django and ran into some
trouble when i wanted to order specific columns.
What i like to do is order a foreign key related object column in the
list_display view.

I have the following code:

model:

class Subquestion(models.Model):
subquestion_id = models.AutoField(primary_key=True)
subquestion_nr = models.IntegerField()
subquestion = models.CharField(max_length=500)
question = models.ForeignKey(Question)

class Answer_Option(models.Model):
answer_option_id = models.AutoField(primary_key=True)
answer_nr = models.IntegerField()
answer = models.CharField(max_length=500)
subquestion = models.ForeignKey(Subquestion)

admin:

class Answer_OptionAdmin(admin.ModelAdmin):
        def subquestion(self):
                return self.subquestion.subquestion
        def subquestion_question(self):
                return self.subquestion.question.question
        def subquestion_questionnr(self):
                return self.subquestion.question.question_nr
        def questionlist(self):
                return
Questionlist_Question.objects.get(question=self.subquestion.question.question_id).questionlist.questionlist_name

        # creating the short names displayed on the column header
        subquestion_question.short_description = "Question"
        subquestion_questionnr.short_description = "Question Nr"
        questionlist.short_description = "Questionlist"

        *subquestion_questionnr.admin_order_field = 'subquestion'*

        list_display =
['answer',subquestion,subquestion_question,subquestion_questionnr,questionlist]



This code works fine but it orders based on the subquestion_id from the
Subquestion model,
I like to have it ordered based on subquestion_nr. I thought the code should
have been something like subquestion.question_nr
but this gives an error.

Does anyone know how to solve this using the django tools.

Any help is appreciated,

best regards,


Richard Mendes

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to