-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide improved support for django #3701
Comments
|
Manage.py could
All of these are probably better suited for the core python extension though. Not really language server related. See this documentation: Which could be improved, but probably better to do that in the python extension. |
Views.py
def index(request):
pass becomes def index(request: HttpRequest) -> HttpResponse:
pass automatically (line completions maybe?) |
Urls.py
|
Fields with required values should flag an error if those values are missing. Example: class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField()
votes = models.IntegerField(default=0)
|
Could completions for models be driven by the data in the 'migrations' folder? |
Only if I had already responded to the item or you mention me by github id. Is there another item we already closed that's about this topic? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Created an issue to think about whether |
Some ideas from the work done here: Generate type stubs on the fly for django classes |
Comment here makes it seem like Django functions have data automatically sent to them (like pytest fixtures): Type inference would be specific to Django I'd think. Much like pytest fixtures. Needs more investigation to see how this works. |
Looking here: Shows that Django completions for parameter names can include a LOT of stuff. It would be cool to include at least some of these (if not all) in completions for parameters. (much like Pycharm does) |
An example of why the 'generated' keys are useful. Suppose we have these two models (from the Django tutorial): class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0) Both of these objects have hidden (generated) fields.
Example usage: q = Question.objects.get(pk=1)
q.choice_set.create(choice_text='Not Much', votes=0) In this example, pylance would have to know
|
Another idea: Query pattern matching. Urls might have something like so: urlpatterns = [
path("", views.index, name="index"),
path("<int:question_id>/", views.detail, name='detail'),
path("<int:question_id>/results", views.results, name='results'),
path("<int:question_id>/vote", views.vote, name='vote'),
] See here for more information: https://docs.djangoproject.com/en/4.1/topics/i18n/translation/#translating-url-patterns It might be possible to have a general regular expression support? Doesn't seem to be asked for, but maybe as a separate extension. Patterned after what regex101.com does. |
Another obvious example, intellisense in Django templates. This would likely require an entirely different parser. Yeah definitely. Django's template language is not python. Example, this is how you concat two strings:
|
There are predefined globals that can be set that have special meaning. It would be nice if they:
Example - a Urls.py: from django.urls import path
from . import views
app_name = 'polls'
urlpatterns = [
path("", views.index, name="index"),
path("<int:question_id>/", views.detail, name='detail'),
path("<int:question_id>/results", views.results, name='results'),
path("<int:question_id>/vote", views.vote, name='vote'),
]
https://docs.djangoproject.com/en/4.1/topics/http/urls/#how-django-processes-a-request |
Warning in forms that don't use the csrf_token tag |
@diego351, @luabud pointed this extension out to me: https://marketplace.visualstudio.com/items?itemName=tonybaloney.python-task-provider That provides commands for manage.py. Thought that might be useful for you. |
Thanks! How the initial support is going? Please let me know if you need anything django related |
@diego351 Honestly, we're still in the investigation phase, trying to figure out what to do first. Any more suggestions of things that you'd like to see or any other features you've seen elsewhere would be a big help. Thanks for asking. |
Another idea: #3874 (comment) Supporting other languages inside of strings. Might also how we implement DTL support. Ship a separate language server just for the DTL parts. |
@rchiodo |
@dakotahorstman do you mean like option 2 that @diego351 mentioned? |
Albeit, I split my |
@rchiodo I mean all settings, not just model definitions. Like regular intellisense, if I were to type |
@dakotahorstman can you share your source? It would help to have an example. |
@rchiodo Unfortunately, I can't due to it being a closed-source application. The most bare-bones Django project can be used though. Here's a screenshot of my application's structure if it's any benefit:
All my request is, if I import I can try to provide a GIF if that would be more beneficial? |
This comment was marked as resolved.
This comment was marked as resolved.
Oh no wait I see what you mean. You want the 'settings' object from django to dynamically have these other 'settings' on it. |
@rchiodo Exactly, yes! Plus the ones Django already ships with if possible. |
More Feedback
|
Solution Ideas for previous comment:Query list completions
Being able to see object tables
Snippets for django related stuff
Django debug toolbar
Show more information about models and other classes
Tables are hard to make in html
Data sent to view is hard to get correct
|
Related issue where we could provide IntelliSense (similar to pytest extension) where all of the model's attributes are mapped to kwargs -- #4370 |
For anyone interested, I started This article goes into more detail. |
Has anyone mentioned support for the auto-generated "id" field? |
I don't believe the 'id' field is mentioned explicitly but it generally follows under this item: #3704. I believe @Viicos work on autotyping would be relevant too. We're discussing doing something similar to what @Viicos has done but generating the type stubs inside of pylance as you type in your code. |
Nice to hear your are also planning on exploring this solution. I did face some challenges though, do not hesitate to let me know if you want to hear more details about it |
MVP idea:
MVP Python Core?
The text was updated successfully, but these errors were encountered: