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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:52:00+00:00 2026-06-14T00:52:00+00:00

how do you delete a ManyToMany relationship in django. how will youu remove m2m

  • 0

how do you delete a ManyToMany relationship in django. how will youu remove m2m then delete the foto this is my models below thanks

class Picture(models.Model):
    owner = models.ForeignKey(User,blank = True)
    caption = models.CharField(max_length=150, blank=True, null=True)
    image = ImageField(upload_to='images/',blank = True, null = True)

class Land(Properies):
    photo = models.ManyToManyField(Picture,blank=True,related_name='Land_Pictures',null = True)

i have tried to delete it this way

checked_list = []
start = 1            
land_photos = sorted(list(land.photo.select_related()),reverse =True)
while start < 8:
    photo = 'photo%s' % start
    checked = form.cleaned_data[photo]
    if checked != None:
        checked_list.append(land_photos[start - 1])
        start += 1            
for a_foto in checked_list:
     land.photo.remove(a_foto)
     try:
         a_foto.remove_all_file()
         a_foto.delete()
     except OSError:
         pass

and then i get an error like this

Exception Type:     AssertionError
Exception Value:    
Picture object can't be deleted because its id attribute is set to None.
  • 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-14T00:52:02+00:00Added an answer on June 14, 2026 at 12:52 am

    Documentation:

    >>> land.photo.remove(some_picture)
    

    Or the other way around, using the provided related_name argument:

    >>> picture.Land_Pictures.remove(some_land)
    

    By default, without related_name, it would be:

    >>> picture.land_set.remove(some_land)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to delete/remove call log from application. I am doing like this this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,null,null); it
I have a ManyToMany relationship with one of my Models. On deleting a child,
I have an entity that has a ManyToMany relationship with itself: @Entity public class
I have two models, say : BlogPost(title, message) Tags(name) Both have a ManyToMany relationship
I am trying to remove a ManyToMany relationship inside Doctrine 2. I have two
$(.delete).click( function() { var thesender = this; $(thesender).text(Del...); $.getJSON(ajax.php, {}, function(data) { if (data[result])
I am trying to delete a cookie with this function , but it doesnt
How I can delete an object which I had added before with this code.
I got issue with bi-directional ManyToMany relationship caching First side mapping : HasManyToMany(x =>
I have a couple of simple objects that have a many-to-many relationship. Django has

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.