Checking for foreign key in clean method - Django 1.77 vs 1.8

19 views
Skip to first unread message

Graham Oliver

unread,
Apr 16, 2015, 6:02:19 AM4/16/15
to django...@googlegroups.com
Hi guys
I have some code in a clean() method that works ok on Django 1.77 but stops working in 1.8

The scenario

class Span(models.Model):

    happening = models.ForeignKey('Happening', blank = True, null = True)
    soul_class = models.ForeignKey('SoulClass', blank = True, null = True)


In the clean() method of the Span class I have a check as follows
    if self.happening:
        foo

    if self.soul_class:
        bar

This was working fine in Django up to 1.77 but when I upgrade to Django 1.8 both self.happening *and* self.soul_class are None.

The primary difference appears to be the value of _soul_class_cache as follows.....

The Span object in 1.77 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>}

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, 'end_time': datetime.time(15, 0), 'id': None, 'start_date': datetime.date(2015, 4, 16)}

Any ideas?
Cheers
g
Reply all
Reply to author
Forward
0 new messages