AutoRefresh model field (filled in by a trigger)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AutoRefresh model field (filled in by a trigger)

Eugene I. Mogilevsky-2

Hi,
I have some fields in a model which are filled in by before_insert
trigger.
Is there any right way to autorefresh them after the object is
inserted, besides requesting a new instance of the object by
model.objects.get() method?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: AutoRefresh model field (filled in by a trigger)

Malcolm Tredinnick

On Wed, 2009-08-12 at 04:55 -0700, Evgeny wrote:
> Hi,
> I have some fields in a model which are filled in by before_insert
> trigger.
> Is there any right way to autorefresh them after the object is
> inserted, besides requesting a new instance of the object by
> model.objects.get() method?

You have one perfectly good method and you want another one instead? :-)

Seriously, use get(pk=my_obj.pk). It's designed to retrieve single
instances from the database. You could do

        filter(id=my_obj.pk).values("field_1", "field_2", ...)
       
but it's not going to be significantly faster unless your model has
massive fields (leading to other problems) and it reads a bit less
comprehensibly in the code.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---