run terminal code inside project

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

run terminal code inside project

Mory Sam

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: run terminal code inside project

Abdul Madebari
Python manage.py shell


On Wed, 4 Nov 2020, 17:55 Mory Sam, <[hidden email]> wrote:

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANPdr5HXDuY9tQPPW826kndcUW0TioYYaKp0_nNwtckZ_dNQAw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: run terminal code inside project

Andréas Kühne
In reply to this post by Mory Sam
You can't do that really.

What is it you want to accomplish?

You can call management commands from inside django - but it doesn't really make any sense to do so. Especially the migrate command?

So what is it you want to do? Then perhaps we can help you with a solution?

Regards,

Andréas


Den ons 4 nov. 2020 kl 15:56 skrev Mory Sam <[hidden email]>:

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCdWvrMpVJyMxQ6DOVTVXt_QzAfWYK3qPdxfKUHYKAk0nA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: run terminal code inside project

Mory Sam
hi  Andréas  
I want to save the models generated by the ogrinspect command in a new file and be able to automatically create a table in the database using this saved model and then import my vector data automatically into the created table To.
؟Now my problem is how can I introduce the newly created model file as a model to django and it automatically creates a table for me without a terminal command.
Thank you for your answer
[hidden email] در تاریخ پنجشنبه ۵ نوامبر ۲۰۲۰ ساعت ۱۳:۰۷:۳۴ (UTC+3:30) نوشت:
You can't do that really.

What is it you want to accomplish?

You can call management commands from inside django - but it doesn't really make any sense to do so. Especially the migrate command?

So what is it you want to do? Then perhaps we can help you with a solution?

Regards,

Andréas


Den ons 4 nov. 2020 kl 15:56 skrev Mory Sam <[hidden email]>:

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e59da9e-9350-4864-acac-87bfa574fa3cn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: run terminal code inside project

Andréas Kühne
I would say that that's even worse?

Django doesn't like changing the database when you are running. I think you need to rethink how you want to use django - because this isn't a usecase I think is even possible.

What you would need to do is first create the models.py file, update the database and then reload the configuration. This would create so many issues that I don't think this is really a valid approach.

Med vänliga hälsningar,

Andréas


Den tors 5 nov. 2020 kl 11:39 skrev Mory Sam <[hidden email]>:
hi  Andréas  
I want to save the models generated by the ogrinspect command in a new file and be able to automatically create a table in the database using this saved model and then import my vector data automatically into the created table To.
؟Now my problem is how can I introduce the newly created model file as a model to django and it automatically creates a table for me without a terminal command.
Thank you for your answer
[hidden email] در تاریخ پنجشنبه ۵ نوامبر ۲۰۲۰ ساعت ۱۳:۰۷:۳۴ (UTC+3:30) نوشت:
You can't do that really.

What is it you want to accomplish?

You can call management commands from inside django - but it doesn't really make any sense to do so. Especially the migrate command?

So what is it you want to do? Then perhaps we can help you with a solution?

Regards,

Andréas


Den ons 4 nov. 2020 kl 15:56 skrev Mory Sam <[hidden email]>:

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e59da9e-9350-4864-acac-87bfa574fa3cn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCdxOeknYUFFTWouOXffconqMDomixq6r-GJYmRejVS4yQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: run terminal code inside project

David Nugent
In reply to this post by Mory Sam
Hint: as Andréas implied, it is always a good idea to state the problem you're trying to solve instead of posing a question about what you think the solution is. :-)  Ends up saving a bunch of time.

Short answer for your solution:

manage.py can be run as a subprocess in python, like any other system command. It does not require a terminal, although running manage.py tasks - specifically those that generate and install migrations - may have issues with a concurrently running django application.

In fact, you don't even need manage.py - it does very little on its own after setting DJANGO_MODULE_SETTINGS - check it out.

Longer answer that addresses the actual problem:

What you describe (generating, installing and using new models in a running django instance) should be doable without the need to use manage.py. You will need some understanding of django internals and hooks and you may need some way of reloading the server or responding to django signals to see the new models... See the caveat above.

I never tried this so have no direct experience but I'm sure there are examples on how to do this out there. To get you started, check out this stackoverflow post that describes the issue I refer to above and this pypi module that might provide a solution.

Regards /d

On 5 Nov 2020, at 21:38, Mory Sam <[hidden email]> wrote:

hi  Andréas  
I want to save the models generated by the ogrinspect command in a new file and be able to automatically create a table in the database using this saved model and then import my vector data automatically into the created table To.
؟Now my problem is how can I introduce the newly created model file as a model to django and it automatically creates a table for me without a terminal command.
Thank you for your answer
andrea...@hypercode.se در تاریخ پنجشنبه ۵ نوامبر ۲۰۲۰ ساعت ۱۳:۰۷:۳۴ (UTC+3:30) نوشت:
You can't do that really.

What is it you want to accomplish?

You can call management commands from inside django - but it doesn't really make any sense to do so. Especially the migrate command?

So what is it you want to do? Then perhaps we can help you with a solution?

Regards,

Andréas


Den ons 4 nov. 2020 kl 15:56 skrev Mory Sam <mory...@...>:

hi all 

How to use django terminal codes inside your project code 

example : " python manage.py migrate " code run inside views.py , not terminal

thanks


-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@....
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08797f34-a4c5-422b-9548-9902c20d2bf3n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e59da9e-9350-4864-acac-87bfa574fa3cn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6EB0CC48-C218-4ED4-ABE4-08FC3A8155D6%40uniquode.io.