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 6909481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:41:41+00:00 2026-05-27T08:41:41+00:00

I am writing a forums app for my final project in class and I

  • 0

I am writing a forums app for my final project in class and I am trying to write a form for creating a new thread, Basically all I need it to do is

username: text box here

Name of thread: Text box here

Post: text box here

I want to do this in forms.py instead of making a template for it.

url(r"^(.+)/new_thread/$", new_thread, name="thread_new_thread"),

That’s my url thread

def list_threads(request, forum_slug):
    """Listing of threads in a forum."""
    threads = Thread.objects.filter(forum__slug=forum_slug).order_by("-created")
    threads = mk_paginator(request, threads, 20)
    template_data = {'threads': threads, 'forum_slug': forum_slug} 
    return render_to_response("forum/list_threads.html", template_data, context_instance=RequestContext(request))

That is my list_threads view, I have a button that should link to the forms.py version of my new thread post

class Thread(models.Model):
    title = models.CharField(max_length=60)
    slug = models.SlugField(max_length=60)
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(User, blank=True, null=True)
    forum = models.ForeignKey(Forum)

    class Meta:
        unique_together = ('slug', 'forum', )

    def save(self, *args, **kwargs):
        self.slug = slugify(self.title)
        super(Thread, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('forum_list_posts', args=[self.forum.slug, self.slug])

    def __unicode__(self):
        return unicode(self.creator) + " - " + self.title

    def num_posts(self):
        return self.post_set.count()

    def num_replies(self):
        return self.post_set.count() - 1

    def last_post(self):
        if self.post_set.count():
            return self.post_set.order_by("created")[0]

This is my thread model

Any suggestions?

  • 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-27T08:41:42+00:00Added an answer on May 27, 2026 at 8:41 am

    Read the documentation:

    https://docs.djangoproject.com/en/dev/topics/forms/modelforms/

    I guess that the Thread has a model.

    class ThreadForm(ModelForm):
    
        def __init__(self, forum, user, *args, **kwargs):
            super(ThreadForm, self).__init__(*args, **kwargs)
            self.forum = forum
            self.user = user
    
        def save(self):
            thread = super(ThreadForm, self).save(commit=False)
            thread.forum = self.forum
            thread.creator = self.user
            thread.save()
            return thread
    
        class Meta:
            model = Thread
            exclude = ('slug', 'created', 'creator', 'forum') 
    

    In your views:

    def thread_add(self, forum_id):
        data = None
        if request.method == 'POST':
            data = request.POST
        forum = Forum.objects.get(id=form_id)
        form = ThreadForm(forum=forum, user=request.user, data=data)
        if form.is_valid():
            form.save()
            .............
        return render_to_response .....
    

    In your model left a field to “Post: text box here”

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

Sidebar

Related Questions

I'm writing a webcam app and I need to write and read about 15
Am writing a new C# web forms app and there is a strong possibility
I'm writing a basic little forums web app (for fun and to sharpen the
I'm writing an app (.NET Compact Framework 3.5 on PocketPc 2003) I'm trying to
I'm writing an iPhone app which works against my own server. Basically, it's a
I am writing a simple win forms app in C#. There is a method
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
I am writing an app that should run on Omnia i900, and this device
I am writing a Django app for use in a country where they use
I am writing a C# form based application and was wondering how the screen

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.