Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:07:07+00:00 2026-05-30T05:07:07+00:00

Im building a customized comments app for django, using django comments itself. Ive followed

  • 0

Im building a customized comments app for django, using django comments itself. Ive followed https://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/ to the letter, and I have 2 issues, one is that my custom comments instances do not give content_object.

So when I try the following I get nothing

c = CommentWithFile.object.get(id)=1 
c.content_object

And two, my comments are not taking the uploading the files I add within the form of the customized comments.

Another thing that I would like to do is to notify by mail, a list of specific users every time someone comments on an specific topic, but I would like to add to the notification a url or the title of the topic the comment was posted on, how could I do this?

My custom comment model.

def upload_path(instance, filename):
    return '/'.join(['uploads','comment_archives', filename])

class CommentWithFile(Comment):

    comment_file = models.FileField(max_length=255, upload_to=upload_path, 
        blank=True, null=True)
    notify = models.BooleanField(_("Notificar usuarios"))

    @property
    def fileobject(self):
        if self.comment_file:
            return FileObject(self.comment_file.path)
        return None

My custom model form

class CommentFormWithFile(CommentForm):
    comment_file = forms.FileField(label=_("Archivo"), required=False)
    notify = form.BooleanField(label=_("Notificar usuarios"))

    def get_comment_model(self):
        # Use our custom comment model instead of the built-in one.
        return CommentWithFile

    def get_comment_create_data(self):
        # Use the data of the superclass, and add in the title field
        data = super(CommentFormWithFile, self).get_comment_create_data()
        data['comment_file'] = self.cleaned_data['comment_file']
        data['notify'] = self.cleaned_data['notify']
        return data

And in the init.py

from apps.comments.models import CommentWithFile
from apps.comments.forms import CommentFormWithFile

def get_model():
    return CommentWithFile

def get_form():
    return CommentFormWithFile

The admin file for my commentwithfile

from apps.comments.models import CommentWithFile

class CommentWithFileAdmin(admin.ModelAdmin):
    pass

admin.site.register(CommentWithFile, CommentWithFileAdmin)

Im using django 1.3.1, and have django notifications in order to notify user of comments.

Thank you everyone!

==== UPDATE ====

Here is the comment form template

{% load comments i18n %}
<form action="{% comment_form_target %}" method="post">{% csrf_token %}
  {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
  {% for field in form %}
    {% if field.is_hidden %}
      <div>{{ field }}</div>
    {% else %}
      {% if field.errors %}{{ field.errors }}{% endif %}
      <p
        {% if field.errors %} class="error"{% endif %}
        {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
        {% if field.label == 'Comentario' or field.label == 'Archivo' %}
        {{ field }}
        {% endif %}
      </p>
    {% endif %}
  {% endfor %}

  <div class="actions">
    <input type="hidden" name="next" value="{{ request.path }}" />
    <input type="submit" name="post" class="submit-post" value="{% trans "Post" %}" />
    <input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
  </div>
</form>

An heres how I render this form in other templates

    {% get_comment_form for archive as form %}
    <h4>Comentar</h4>

    <div class="main_comment" id="comment_form">
        {% render_comment_form for archive %}
    </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:07:08+00:00Added an answer on May 30, 2026 at 5:07 am

    2 things are necessary for your system to work:

    1. The tag has an enctype attribute allowing file uploads, e.g. <form enctype="multipart/form-data" method="post" action="">, or the browser will not send the file

    2. The form is instanciated with both request.POST and request.FILES, e.g. form = form_class(request.POST, request.FILES). Else the FileField will not have any value.

    So really what’s missing from your topic are:

    1. The form HTML and

    2. The view python code, hint: make sure you inspect request.FILES there BTW

    For me to make a perhaps more specific answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a Django app on a VPS. I am not very experienced with setting
Building a Django app. Class Company(models.Model): trucks = models.IntegerField() multiplier = models.IntegerField() #capacity =
building a site using PHP and MySQL that needs to store a lot of
I am building an installer for my windows app and have done this through
I am building a basic app interface which will have a mixture of text,
I've been working as a flex dev for many years, building really complex apps.
I'm building an app which would have to have the ability to show my
I'm building a Rails 3 app on Heroku. Right now my error pages and
I am building a customized add in for our CRM system. When end users
We are building an email alert system which needs to send customized emails in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.