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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:29:29+00:00 2026-05-28T01:29:29+00:00

I learning python and django and trying to make some sort of simple forum.

  • 0

I learning python and django and trying to make some sort of simple forum. I created models:

class Board(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField(blank = True)

class Post(models.Model):
    board = models.ForeignKey(Board)
    ...

I’d like to have post numeration starting from 0 for every board. How i should change my models to achieve that? What am i doing wrong?

  • 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-28T01:29:29+00:00Added an answer on May 28, 2026 at 1:29 am

    I don’t know if you’re talking about using the primary key as the post ID, but that won’t work if you want it to start with 0 for each board. I’d recommend adding another field on your Post model and manage it yourself on the save method. Example:

    class Post(models.Model):
        board = models.ForeignKey(Board)
        post_count = models.PositiveIntegerField(default=0)
    
        def save(self, *args, **kwargs):
            if not self.id:
                self.post_count = self.board.post_set.count()
            super(Post, self).save(*args, **kwargs)
    

    Edit: As Brian points out, there could be problems when posts are deleted. This would result in duplicate post_ids. You could add a deleted field to the model to “fake” delete posts (don’t show when deleted = True) which would keep the post_id counting accurate.

    Edit 2: You could set the post_count to be equal to the maximum post count for this board + 1 (or 0 if the count is 0)

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

Sidebar

Related Questions

I'm learning Python and django at the same time. I'm trying to create an
In the process of learning Django and Python. I can't make sense of this.
I'm learning Python now because of the Django framework. I have been a Perl
I am learning Python for a class now, and we just covered tuples as
I've been learning python for a while now with some success. I even managed
I am learning Python and trying to figure out an efficient way to tokenize
im currently learning python (in the very begining), so I still have some doubts
The model: class Product(models.Model): name = models.CharField(max_length = 128) def __unicode__(self): return self.name class
I'm learning Python and Django using the Eclipse Pydev plugin. I want the internal
As I'm currently learning Django / Python, I've not really been using the concept

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.