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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:44:28+00:00 2026-06-05T19:44:28+00:00

Suppose I have got a model ArticleVersion in my project which is defined as:

  • 0

Suppose I have got a model ArticleVersion in my project which is defined as:

class ArticleVersion(models.Model):  

    article = models.ForeignKey(Article)
    version = models.PositiveIntegerField()
    content = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    media_type = models.ForeignKey(MediaType)
    author = models.ForeignKey(User, null=True)

When the user fills in the form for this model I check whether the content of version from the form is different and if it is I create a new version. Actually now it looks something like this

   if self.old_content != updated_version.content:
        # create new version if content is different
        updated_version = self.article.articleversion_set.create(
            article=self.article,
            version=self.article.latest_version.version + 1,
            content=updated_version.content,
            media_type=updated_version.media_type,
            author=updated_version.author
        )

But if I put more fields in the model it would be too verbose. I was wondering is there a way to do such things in Django more concisely?

  • 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-06-05T19:44:30+00:00Added an answer on June 5, 2026 at 7:44 pm

    You can just set article.pk to None, and when you save a new entry will be created.

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

Sidebar

Related Questions

I've got a model that looks like class order(models.Model): user = models.ForeignKey(some_user) number =
I've got some models set up like this: class AppGroup(models.Model): users = models.ManyToManyField(User) class
Suppose there are only two type of model objects. Tag Article Article can have
I got a question about C++ function call. Suppose I have defined a function
Suppose I have the following HTML: <div id=Wrapper> <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>
Suppose I have a ASP.NET Web API controller that uses a service, which in
Suppose you have got a bunch of files written in C, C++ or Fortran,
Suppose in Yii Framework I have the attributes for the model like this field_1
I have a user model in which I have a method for seeing if
Suppose I am doing matchmaking of users and games. I have models containing users

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.