Add custom python Django commands that can easily be executed from VS (i.e. when you right click Django project -> Python -> Django Migrate / run server / etc.)
Glad you asked :) This is already possible, but we consider it sufficiently advanced that we don't provide UI for it.
If you look at Microsoft.PythonTools.Django.targets you'll see how we've added the existing ones. You can use these as a template and add them into your own This is essentially the code you'll need (I've simplified it a bit from what I linked above - you don't need to use If you have ideas for commands that would be useful for everyone, feel free to add them to the file I linked above and send a pull request. We can handle adding resource strings if you don't want to. The "documentation" for this feature is in Microsoft.PythonTools.targets.pyproj file, or your own .targets file and then add `resource: syntax for labels, you can just put in the text). <PropertyGroup>
<PythonCommands>MyCommand;$(PythonCommands)</PythonCommands>
</PropertyGroup>
<Target Name="MyCommand"
Label="My Django Command"
Returns="@(Commands)">
<CreatePythonCommandItem Target="$(StartupPathOrManagePy)"
TargetType="script"
Arguments="check"
WorkingDirectory="$(WorkingDirectory)"
Environment="DJANGO_SETTINGS_MODULE=$(DjangoSettingsModule)"
ExecuteIn="Repl:My Django REPL Title">
<Output TaskParameter="Command" ItemName="Commands" />
</CreatePythonCommandItem>
</Target>
Thanks so much! Super helpful :)
For Django, I use a test DB for integration testing - there are 2 cmds I use:
manage.py dumpdata > db.jsonmanage.py testserver db.jsonEach time you start the test server, the DB is in the exact same state, i.e. any changes you make are discarded when you stop the server.
If you think these will be useful I'll send a pull request
Most helpful comment
Glad you asked :) This is already possible, but we consider it sufficiently advanced that we don't provide UI for it.
If you look at Microsoft.PythonTools.Django.targets you'll see how we've added the existing ones. You can use these as a template and add them into your own
.pyprojfile, or your own.targetsfile and then add `This is essentially the code you'll need (I've simplified it a bit from what I linked above - you don't need to use
resource:syntax for labels, you can just put in the text).If you have ideas for commands that would be useful for everyone, feel free to add them to the file I linked above and send a pull request. We can handle adding resource strings if you don't want to. The "documentation" for this feature is in Microsoft.PythonTools.targets