Foreign key validation in model cleanup method - Django 1.7.7 vs 1.8

I have some code in the clean () method that works fine on Django 1.7.7, but stops working in 1.8

Scenario

class Span(models.Model):
    happening = models.ForeignKey('Happening', blank = True, null = True)
    soul_class = models.ForeignKey('SoulClass', blank = True, null = True)

      

In a clean()

class method Span

, I have a check as follows

if self.happening:
    foo

if self.soul_class:
    bar

      

This worked fine in Django up to 1.7.7, but when I upgrade to Django 1.8, both self.happening and self.soul_class are None.

The main difference seems to be the meaning _soul_class_cache

as follows:

The Span object in 1.7.7 looks like

{'end_date': None,
 'id': None, 
 '_state': `<`django.db.models.base.ModelState object at 0x7ff046ac1320`>`, 
 'start_date': datetime.date(2015, 4, 16), 
 'soul_class_id': None, 
 'end_time': datetime.time(14, 12), 
 'happening_id': None, 
 '_happening_cache': None, 
 'start_time': datetime.time(14, 12), 
 '_soul_class_cache': `<`SoulClass: Chi Kung`>` # <-- Here
}

      

In 1.8

{'start_time': datetime.time(14, 0), 
 'end_date': None, 
 'soul_class_id': None, 
 '_state': `<`django.db.models.base.ModelState object at 0x7f88d698d2e8`>`, 
 'happening_id': None, 
 '_happening_cache': None, 
 '_soul_class_cache': None, # <-- Here 
 'end_time': datetime.time(15, 0), 
 'id': None,
 'start_date': datetime.date(2015, 4, 16)}

      

Any ideas?

+3
django


source to share


No one has answered this question yet

Check out similar questions:

568
How to temporarily disable foreign key constraint in MySQL?
453
How to check Django version
404
Extending user model with custom fields in Django
208
Django Model () vs Model.objects.create ()
130
Django self-hosted foreign key
20
Django foreign key model
3
What's wrong with my .py machines?
2
AttributeError Object - "Services" has no attribute "service_price"
0
Django model form - pure method with foreign key
0
How can I check if Django Signal is working?



All Articles
Loading...
X
Show
Funny
Dev
Pics