Re: Arbitrary Properties from code

2010-07-01 Thread Bill Freeman
mood = Emotion.objects.get(mood='thoughtful') The above raises DoesNotExist if the emotion hasn't been defined. If you want to raise a different one, then catch this one and raise your own. Then use mood in your query on the person's emotions. On Thu, Jul 1, 2010 at 10:31 AM, Doug Warren wrote

Re: Arbitrary Properties from code

2010-07-01 Thread Daniel Roseman
On Jul 1, 3:31 pm, Doug Warren wrote: > Let's say I have some models that look like: > > class Emotion(models.Model): >     mood = CharField(unique=True) > > class Person(models.Model): >     emotions = ManyToManyField(Emotion) >     name = CharField() > > angry = Emotion(mood='angry') > angry.sav

Arbitrary Properties from code

2010-07-01 Thread Doug Warren
Let's say I have some models that look like: class Emotion(models.Model): mood = CharField(unique=True) class Person(models.Model): emotions = ManyToManyField(Emotion) name = CharField() angry = Emotion(mood='angry') angry.save() sad = Emotion(mood='sad') sad.save() bob = Person(nam