Django: How to customize the admin form for specific model

145 views
Skip to first unread message

Shoaib Ijaz

unread,
Jan 24, 2015, 2:31:02 PM1/24/15
to django...@googlegroups.com

First of all I apologize the question title can be unrelated to my query. I am also confused what I want to do because I am less familiar with django.

I want to create simple comment system. The requirement is clear that user can post comment with multiple images.Every comment should have reply. so I created following models.

#comment table 
class Comments(models.Model):
    parent = models.ForeignKey('self',null=True) // for comment reply
    description = models.TextField(max_length=1000, blank=False, null=False)

    class Meta:
        db_table = u'comments'


#images table
class CommentImages(models.Model):
    comment = models.ForeignKey(Comments)
    image = models.CharField(max_length=250, blank=False, null=False)

    class Meta:
        db_table = u'comments_images'

I have query about admin side how can i manage these things?

I want to show images list when admin view the specific comment.

Admin can view replies of specific comment.

Here i draw the example. enter image description here

So I dont want to ask about coding. I want to know what techniques will be used to change the admin view. I am using admin panel for others models too so I want to change the specific model view.

How can I get these things? Thank you

Thomas Rega

unread,
Jan 24, 2015, 3:36:51 PM1/24/15
to django...@googlegroups.com
You could get this things done by customization of the corresponding admin template: templates/admin/change_form.html


Good Luck
TR

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0fb17b82-042a-4d45-a8dd-bb842d94923c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Jan 27, 2015, 3:11:45 PM1/27/15
to django...@googlegroups.com
Hi,

You could have the images be inline:

class CommentImageInline(models.TabularInline):
    model
= CommentImage
    extra
= 0

class CommentAdmin(models.ModelAdmin):
    inlines
= [CommentImageInline]

Though, you may need to use a custom widget to get the actual images to show up.

Collin

carlos

unread,
Feb 3, 2015, 12:41:15 PM2/3/15
to django...@googlegroups.com
Hi, in addition Collin answer you need use sorl-thumbnail in show picture in admin

Cheers

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages