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

  • Home
  • SEARCH
  • 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 7601709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:13:49+00:00 2026-05-30T23:13:49+00:00

I have the following models in an app. Lesson Student Evaluation Parent Lesson and

  • 0

I have the following models in an app.

Lesson
Student
Evaluation
Parent

Lesson and Student have a m2m relationship through Evaluation.

I have an inline formset which allows me to create evaluation records at the same time I create a new lesson.

I would like to sort the formset before I process it so that I can put all the records that share a common parent record together and carry out some additional tasks when saving the records.

Here’s a simplified example:

EvaluationFormset = inlineformset_factory(Lesson, Evaluation, extra=1, max_num=10)


if request.method == 'POST': 
    form = LessonForm(request.POST, instance=lesson, user=request.user)
    formset = EvaluationFormset(request.POST, instance=lesson)

    if form.is_valid() and formset.is_valid():
        lesson = form.save()
        models = formset.save(commit=False)

        #Before I do this, I need to sort the formset based on evaluation.student.parent.
        #In the loop, I will perform an additional the first record for each parent

        for i in models:
            i.user = request.user
            i.lesson = lesson
            i.save()

Is there any easy way to this in Django?

Any advice appreciated.

Thanks.

  • 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-30T23:13:51+00:00Added an answer on May 30, 2026 at 11:13 pm

    Try something like this:

    models = list(models) # maybe this can be omitted
    models.sort(key=lambda e: e.student.parent)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Models set up in my app: Lesson Student Evaluation The
I have the following models in my Django app. How can I from the
I have the following Node.js directory structure. |--app/ |--app.js |--routers/ |--index.js/ |--models/ |--schemas.js |--post.js
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have the following 2 models in my Google App Engine datastore: class Search(db.Model):
I have a rails 3.1 app with the following Models: class Post < ActiveRecord::Base
I have the following models in my app (only showing the related scopes): class
I have the following code: # app/models/part.rb class Part < ActiveRecord::Base has_many :lots #
I have the following models in a Rails 3 app, and select requirement: class
I have a Rails 2.3 app with the following models. class Message << AR::Base

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.