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
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
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
3 matches
Mail list logo