Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Checking value of related field in custom save method [RSS Feed]

#1 March 25, 2008 03:45:14

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Checking value of related field in custom save method


I want to do the following but it doesn't seem to be working.
Basically, once an enrollment record has been saved its parent cannot
be changed:

class school (models.Model):
name = models.CharField()

class enrollment(models.Model):
school = models.ForeignKey(School)

def save(self):
if self.id != None:
enrollment = Enrollment.objecs.get(id=self.id)
if enrollment.school != self.school:
raise TypeError, "The school of an enrollment record
cannot be modified."

I'm getting the following exception:
raise self.field.rel.to.DoesNotExist
DoesNotExist

Do children not have access to their parents in their save methods?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 March 25, 2008 05:40:03

m.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Checking value of related field in custom save method


Nevermind. I had a typo in my test code that was setting
enrollment.school to a value that didn't exist.

On Mar 24, 10:45 pm, meppum <> wrote:
> I want to do the following but it doesn't seem to be working.
> Basically, once an enrollment record has been saved its parent cannot
> be changed:
>
> class school (models.Model):
>    name = models.CharField()
>
> class enrollment(models.Model):
>    school = models.ForeignKey(School)
>
>    def save(self):
>        if self.id != None:
>           enrollment = Enrollment.objecs.get(id=self.id)
>           if enrollment.school != self.school:
>              raise TypeError, "The school of an enrollment record
> cannot be modified."
>
> I'm getting the following exception:
>     raise self.field.rel.to.DoesNotExist
> DoesNotExist
>
> Do children not have access to their parents in their save methods?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » Checking value of related field in custom save method [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support