Signals

9 views
Skip to first unread message

Yoo

unread,
Jun 16, 2019, 2:26:49 PM6/16/19
to Django users
Hi. the following code is kinda wonky, so here's the context. I have two models:

The url_id field is supposed to be an auto increment field; however, since it's not the primary key, I can't. Obviously, I could make a function that autoincrements for me, but I suppose I simply need this use-case. 

Thus, with the model StuffIDTable, the id is supposed to be the table names (i.e. Stuff1 and Stuff2) and the last_number is supposed to be the latest number that a url_id used (as in the highest number used by a record of a certain table with url_id).

I'm not sure where to go with this. I was thinking of using signals to find the latest number used, then update it by incrementing last_number by one, then sending another signal back for Stuff1 or Stuff2 to save in url_id. Not only that, but what would the signal code look like? How do I even code a signal code? 

In the models, do I need a def save(self, *args, **kwargs): 
then some kind of "signals" code provided by Django? Post_save, pre_save? Just... confusing...

The previous paragraphs might not have made much sense, so if clarification of a certain part (or all of it) is needed, don't hesitate to immediately bash on me :)
Reply all
Reply to author
Forward
0 new messages