What am doing wrong in below admin & model.py; I expect the list display 
will display values of all three column values from list_display, but it 
doesnt; Particularly, the values of item_status & solution note not getting 
shown in my admin view;
Admin.py: 

class ItemAdmin(admin.ModelAdmin):
    def item_status(self,instance):
        comment1 = instance.comment_set.all()
        return comment1.get_status_display()
    def solution_note(self,instance):
        comment1 = instance.comment_set.all()
        return comment1.body()

    list_display = ('title', 'item_status', 'solution_note')

admin.site.register(Item,ItemAdmin)

Model.py
========
STATUS_CHOICES = (
  (1, 'New'),
  (2, 'In-progress'),
  (3, 'Closed'),
)


class Item(models.Model):
    title = models.CharField(max_length=150)


    def __unicode__(self):
        return self.title



class Comment(models.Model):
    body = models.TextField(blank=True)
    status = models.PositiveIntegerField(choices=STATUS_CHOICES,default=1)
    task = models.ForeignKey(Item)

    def __unicode__(self):
        return self.body

    # Auto-set the item creation / completed date
    def save(self):
        print self.status
        #If Item is being marked closed, set the completed_date
        if (self.status == 3):
             self.date = datetime.datetime.now()
        super(Comment, self).save()

`

=============== when I tried return comment1[0].get_status_display() --> 
values on the admin view page are shown but when I try to add new item, it 
gives me index error pointing to comment1[0] & changelist_view.html 
template issue

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Y4RXrl9ULSoJ.
To post to this group, send email to django-users@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