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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:22:30+00:00 2026-06-16T13:22:30+00:00

I have the following models in my Django app: class Property(models.Model): …various attributes… class

  • 0

I have the following models in my Django app:

class Property(models.Model):
    ...various attributes...

class Booking(models.Model):
    property = models.ForeignKey(
        Property
    )
    ...more attributes...

I implemented the clean() method for Booking which checks various constraints of a Booking. A number of these constraints depend on the association of Booking and Property being in place. For that reason I have the following in the clean() method of Booking:

if self.property is not None:
    ...Property related validations...

Upon entering a new booking in the admin application and just pressing the Save button without entering anything, this generates a DoesNotExist exception on self.property is not None. It’s my understanding that the missing association should be captured by the individual field validation of Django.

When I comment out the clean() method the above doesn’t happen and the missing association is properly flagged as an error when I submit a blank booking form.

I’m obviously missing something but haven’t got a clue what…

  • 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-16T13:22:31+00:00Added an answer on June 16, 2026 at 1:22 pm

    Posting as an answer since it was the answer:

    Have you tried changing your conditional to:

    if hasattr(self, 'property') and self.property is not None

    I’m not sure of the root cause since I deduced the solution based on the error message. I imagine that the Django ORM might create the foreign key association dynamically upon save, so even though it’s a required attribute it hasn’t been created yet since the Booking instance is new and hasn’t been saved.

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

Sidebar

Related Questions

I have the following model in my Django app: class Group(models.model): name=models.CharField(max_length=30) users=Models.ManyToManyField(User) In
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):
In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,)
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I have the following django model: class Article(models.Model): title = models.CharField(max_length = 200) body
I have the following django model with an ImageField: class Pics(models.Model): def file_path(instance, filename):
Lets say, I have following models in my Django app. class EventGroup name =
I've got the following model in my Django app: class Image(models.Model): image = models.ImageField(
I have an existing app with the following model class Contact(models.Model): lastname = models.CharField(max_length=200)

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.