I think if your methods are really complex then the best you can do is
to denormalise your DB.

Make your calculated fields real fields in a table and update them in
model's save method or using signals.
Another way is to make them calculated by DB using triggers or DB
views but I would prefer denormalisation in this case.

If your methods are not that complex then it may be better to write
manager's methods and put query constructing there.

There are several django apps that can help with denormalisation
(http://bitbucket.org/daevaorn/django-composition/src/,
http://github.com/initcrash/django-denorm).

On 28 окт, 19:29, pbzRPA <pbz...@gmail.com> wrote:
> I think my problem is both 1 and 2. What happens when you want to use
> python modules to analyse the extra field?
>
> For Example:
>
> Database table History:
>     id       |  Ordered | Delivered | Invoiced |
>     1              10           15           5
>     2               5            5            3
>
> class History(models.Model):
>     ordered = models.IntegerField()
>     delivered = models.IntegerField()
>     Invoiced = models.IntegerField()
>
>     def compute_problem(self):
>          'here will be code that analyses the above data'
>          if self.ordered > self.delivered:
>              return self.ordered - self.delivered
>          if self.invoiced < self.delivered:
>              return self.delivered - self.invoiced
>          return 0
>
> Ideally I would like to create the virtual scenario:
>
>     id       |  Ordered | Delivered | Invoiced | compute_problem
>     1              10           15           5               -5
>     2               5            5            3               -2
>
> in the view I would like to do the following. Please note that my
> compute_problem is a real basic example and I am sure that the above
> example I could do in SQL but my methods become a lot more
> complicated.
>
> queryset = History.objects.filter().exclude(compute_problem = 0)
>
> I can not modify the database as I am writing add-ons and not creating
> the database myself.
>
> I hope this makes a bit more sense. :)
--~--~---------~--~----~------------~-------~--~----~
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