Question about asking questions and generation in a loop #382
-
Hi, I want to understand how I would attempt to do the following. I tried to find answers in documentation, and other reference implementations and even tests. But they don't all seem to add up. Here's what I want to doI want to generate source code for all the models in a django application along with their templates, views and other files. If you are not familiar with django, that's okay. I will explain. For example, if I have
In essence, I need to loop inside the file as well as on the directory itself. Here's how I thought I would approach thisI wanted to write the model structure in a JSON or YML (list of models and their associated properties. project_name:
type: str
help: Your project name
author_username:
type: str
help: Your username (e.g. on GitHub)
models:
- first:
type: str
help: First model name
- second:
type: str
help: Second model name When I run this the output is:
I wanted copier to recurse and ask questions about first and second. Other possibilitiesInvoking multiple times As an alternative I am thinking about writing a python program where I would read the models data from a JSON or YML and merge that with questions somehow to get the desired outcome. Maybe even run the copy command multiple times with each model. So I want to know:
Asking questions in a loop Second alternative may be to ask questions in a loop, collect answers and then pass them to copy command as DATA and that could do the trick. But here I don't know how to:
I am sort of lost and maybe copier cannot do what I am trying. Please guide. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The short answer is no. Copier is designed to be configurable using a YAML file, which is just data, so it cannot contain logic. However, there are alternative strategies you can follow:
|
Beta Was this translation helpful? Give feedback.
The short answer is no. Copier is designed to be configurable using a YAML file, which is just data, so it cannot contain logic.
However, there are alternative strategies you can follow: