I think you're looking for something like this on a model:

@property
def is_bigger(self):
    return self.a > self.b

-A


On Sat, Jan 5, 2013 at 9:16 AM, Babatunde Akinyanmi <tundeba...@gmail.com>wrote:

> I think you can write a function that returns a > b and then make it a
> getter method with python's property.
>
> i would have given an example but typing code from my phone isn't very
> appealing.
>
> Sent from my Windows Phone
>
> -----Original Message-----
> From: Saqib Ali
> Sent: 1/5/2013 5:50 PM
> To: django-users@googlegroups.com
> Subject: How to add an element of derived data to a Django model?
>
>
>
>
> I have a Django Model as follows:
>
>
>
>
>
> class myModel(models.Model):
>
>
>  a = models.IntegerField()
>
>
>  b = models.IntegerField()
>
>
>
>
> I want to add a models.BooleanField() named c to the myModel class.
> However the value of c is simply derived from a and b so I don't want
> it to be stored in the Database.
>
> I want to c to be True if a > b, otherwise False. I want c to reflect
> the correct/current value even when a and b get modifed. And I want to
> be able to access c using myModel.c just like I can access a and b.
>
>
>
>
> Is there any way to do this?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
>  To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/d3_X6ZCWMGAJ.
>  To post to this group, send email to django-users@googlegroups.com.
>  To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
>  For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to