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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:31:40+00:00 2026-05-30T11:31:40+00:00

Django Newbie question. I have the following model: class Leg(models.Model): drive_date = models.DateField() startpoint

  • 0

Django Newbie question. I have the following model:

class Leg(models.Model):
  drive_date = models.DateField()
  startpoint = models.CharField(max_length=50)
  endpoint = models.CharField(max_length=50)
  start_time = models.TimeField()
  riders = models.ManyToManyField(Rider, blank=True)
  drivers = models.ManyToManyField(Driver, blank=True)
  carpool = models.ForeignKey(Carpool,  blank=True, null=True)

for certain instances of Leg, I want to remove any existing riders and drivers from the Leg model, but NOT delete them from the Rider or Driver Models (not shown) respectively. Can’t figure out how to do it. When I iterate with:

for driver in leg.drivers.all():
    driver.delete()

It appears to delete the actual Driver object, which I don’t want to do.

Any help is greatly 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-30T11:31:43+00:00Added an answer on May 30, 2026 at 11:31 am

    One way I might approach this would be to create a custom manager for the Driver model. Untested code below:

    from django.db import models
    
    class DriverManager(models.Manager):
        def get_query_set(self):
            return super(DriverManager, self).get_query_set().filter(removed=False)
    
    class Driver(models.Model):
        # new stuff to add ...
        removed = models.BooleanField(default=False)
        objects = models.Manager()  # default manager
        active = DriverManager()  # custom manager
    

    Explanation: A new field, removed, is added to the Driver model. Instead of deleting the record, you set it to True and save. Then, where you would normally filter Driver.objects, use Driver.active instead.

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

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I'm a Django newbie who needs your help Have this database model: class Record(models.Model):
Django newbie here. I have two simple models like this: class Fluff(models.Model): # ....
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I am newbie at Django. I have model with a custom method. In view
a newbie question I have a Django project with two applications core and nagios
Django newbie here, I have several types of models, in each of them the
i'm new to django so i'm sorry for my newbie question i have a
Being a Django newbie, I have a question to ask, which should be very
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()

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.