Skip to content
Discussion options

You must be logged in to vote

For those interested, I found a solution by overiding Script as_form() method. Here is the logic:

def as_form(self, data=None, files=None, initial=None):  
    if data is None: # initial form GET request /extras/scripts/Myscript.Myscript/?device=666  
        device = Device.objects.get(id=str(initial['device']))  
        initial['mycf'] = device.custom_field_data['mycf']  
        # other vars ...             
    form = super().as_form(data, files, initial)  
    return form  

This method will be called twice: for GET where data is None and initial contains query params, and for POST where data contains final form data.

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@bistraque
Comment options

Comment options

You must be logged in to vote
1 reply
@bistraque
Comment options

Comment options

You must be logged in to vote
4 replies
@julianstolp
Comment options

@bistraque
Comment options

@adparis99
Comment options

@bistraque
Comment options

Answer selected by bistraque
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants