#29672: Returns an empty model field that is filled with a trigger in the 
database.
-----------------------------------------+------------------------
               Reporter:  folt           |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  2.1
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 my model

 {{{
 blank_and_null = {'blank': True, 'null': True}

 class Message(....):
     ....
     chat_local_id = models.BigIntegerField(
         verbose_name='local id message for chat',
         **blank_and_null)
     ....
 }}}

 I transferred some logic to the trigger database.
 Here is my trigger

 {{{
 CREATE OR REPLACE FUNCTION public.inc_chat_local_id()
      RETURNS trigger
      LANGUAGE 'plpgsql' AS
 $BODY$
 DECLARE
         new_count_message INTEGER;
 BEGIN
         UPDATE v1_chat_chat SET count_message = count_message + 1
                 WHERE id = NEW.chat_id;

         SELECT v1_chat_chat.count_message INTO new_count_message FROM
 v1_chat_chat
                 WHERE id = NEW.chat_id;

         NEW.chat_local_id = new_count_message;

         RETURN NEW;
 END;
 $BODY$;

 DROP TRIGGER IF EXISTS generate_chat_local_id on v1_chat_message;

 CREATE TRIGGER generate_chat_local_id
   BEFORE INSERT
   ON v1_chat_message
   FOR EACH ROW
   EXECUTE PROCEDURE inc_chat_local_id();
 }}}

 It works as I expect
 before insertion requests, it sets the value of chat_local_id
 when I execute the insert query through django
 chat_local_id empty field
 when I re-query this entry, the chat_local_id is set to

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29672>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.60f2afcafd76f81ec5d169f408001311%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to