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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:21:22+00:00 2026-05-19T00:21:22+00:00

I want to check my Foo instance if it belongs to a category yet

  • 0

I want to check my Foo instance if it belongs to a category yet my category is a many to many attribute thus I get "'Foo' instance needs to have a primary key value before a many-to-many relationship can be used." once I try such:

class Category(models.Model):
    name = models.CharField(max_length=120)

class Movie (models.Model):
    poster = models.ImageField(blank=True)
    categories = models.ManyToManyField(Category) 

    def clean(self):
            try:
                self.categories.all().get(db_name="special")
                self.poster.url = u'/media/special_img.png'
            except Category.DoesNotExist:
                pass
  • 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-19T00:21:23+00:00Added an answer on May 19, 2026 at 12:21 am

    You can’t check if Foo belongs to a category yet until you save it. But since it isn’t saved anyway, you can be sure that it doesn’t belong to a category yet.

    One way to check wheter it has been saved already is by using if foo.pk. The pk is the primary key and it will be None if it hasn’t been saved yet.

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

Sidebar

Related Questions

I have an two associative arrayes and I want to check if $array1[foo][bar][baz] exists
I want to check if my many column in datagridview is empty. here my
I have the following problem: I want to check if a website (in a
Essentially, I want to check another object to see if an attribute is set
I am using mount -o bind /some/directory/here /foo/bar I want to check /foo/bar though
I need to check the type of a mock object and want to get
I have a strange problem. I want to check if .ASPXAUTH cookie exists with
I want to have a type hierarchy where only Foo objects are in control
I have a bunch of methods which I want to check some metadata of,
i have the following classes. class base { private function __construct(){ //check if foo

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.