[Answer]-Django AutoField increment


You can just get the last object and increment from here:

query = WebQuery.objects.all().order_by("-id")[0]
new_query = WebQuery.objects.create(user_id = request.user.id,
                                    sent_to = selected_users,
                                    user_query = query,
                                    date_time = date_time,
                                    conversation_id = query.conversation_id + 1)

(assuming that “id” is the primary key of your WebQuery model)

I don’t know if there is a way to do this automatically in a Django model though.

Leave a comment