-
-
Notifications
You must be signed in to change notification settings - Fork 246
Description
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 do
I 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.
So given I have 2 models, I want to ask questions related to each model and then generate code. The models can also be 3/5 or any number.
For example, if I have first and second as models, I would expect to get:
- forms.py (contains definitions for both first and second form).
- templates/first.html
- templates/second.html
In essence, I need to loop inside the file as well as on the directory itself.
Here's how I thought I would approach this
I 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 nameWhen I run this the output is:
author_username? Format: str
🎤 [None]: dsf
models? Format: yaml
🎤 [[{'first': {'type': 'str', 'help': 'First model name'}}, {'second': {'type': 'str', 'help': 'Second model name'}}]]:
create README.md
create .copier-answers.yml
create Makefile
I wanted copier to recurse and ask questions about first and second.
Other possibilities
Invoking 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:
- Is there a way to do this?
- How can I invoke the copy command with additional data that would start asking questions?
- Will it append to answers?
- Will it append to generated files?
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:
- How to invoke the question asking routines that would return me answers to current model.
- Generate multiple files for each model.
- Store answers
I am sort of lost and maybe copier cannot do what I am trying.
Please guide.