Earlier quoted context omitted.
Create a models.py and import there your models from wherever they are. This should do the trick.
Yeah, or another way of splitting up huge models files is to convert models from a module to a package by making a directory models and adding models/__init__.py, models/foo_models.py, models/bar_models.py then doing from .foo_models import * from .bar_models import * in your __init__.py
Learn web development: Django Web Framework
41–50 of 54 posts
Re: Learn web development: Django Web Framework
#42Great to see Mozilla supporting Django. But isn't the official Django tutorial cover all of this, Why not just link to it?
Django's basic tutorial is great to get started, but once you get into the nitty gritty I find myself often going to stacks rather than the docs to get the information I need because the docs get kinda sparse. One example is if you want to forgo modelforms and pass the information from the forms to the model manually through your view (for example because you want to manipulate the information before passing it to th…
Re: Learn web development: Django Web Framework
#43Dumb question, why does the guide suggest that you create an empty folder and then initialize the project from there? (django_test/mytestsite, locallibrary/locallibrary) As far as I can tell, no file, hidden or otherwise, is left in the outer folder.
Re: Learn web development: Django Web Framework
#44If you're curious about how to set up a modern JS frontend on top of Django, I wrote up a tutorial recently. It might be helpful if you're debating between trying a Single Page App approach or some other design: https://medium.com/@theSquashSH/reconciling-djangos-mvc-temp...
Re: Learn web development: Django Web Framework
#45Earlier quoted context omitted.
you reference the model in the view and then tell the view to save it directly to the model using the "model = form field" type syntax to assign value and then .save() method to save. In the form field you are saving from, you write the form field value and then an empty space where the input value goes sort of like "form.cleaned_data.get("field name", " "). The second blank ""is the empty space where the field value…
"The second blank ""is the empty space where the field value goes." I'm not sure I understand what you're saying here, but I don't think this is right. cleaned_data is a dictionary, and so the second argument to get is a default value to use if there is no value corresponding to the key. So, in your example, if there's no value for "formfield1" in cleaned_data, it would return a string with a space in. This is probab…
I just tried your solution with cleaned_data["formfield1"] instead of cleaned_data("formfield1","") and it didn't work for me, it came back with the following error message when I submitted the form:
>'builtin_function_or_method' object is not subscriptable
I think you have to have the empty quotes after the form field and I think that's what's capturing the user input
so here "form.cleaned_data("formfield1","") seems to be telling django the form name and then the second field is where the associated user input goes which is then passed to the model.
Re: Learn web development: Django Web Framework
#46If you're curious about how to set up a modern JS frontend on top of Django, I wrote up a tutorial recently. It might be helpful if you're debating between trying a Single Page App approach or some other design: https://medium.com/@theSquashSH/reconciling-djangos-mvc-temp...
Re: Learn web development: Django Web Framework
#47Earlier quoted context omitted.
"The second blank ""is the empty space where the field value goes." I'm not sure I understand what you're saying here, but I don't think this is right. cleaned_data is a dictionary, and so the second argument to get is a default value to use if there is no value corresponding to the key. So, in your example, if there's no value for "formfield1" in cleaned_data, it would return a string with a space in. This is probab…
Sorry typo, it should be the second blank is the empty space where the user input goes. I just tried your solution with cleaned_data["formfield1"] instead of cleaned_data("formfield1","") and it didn't work for me, it came back with the following error message when I submitted the form: >'builtin_function_or_method' object is not subscriptable I think you have to have the empty quotes after the form field and I think…
so it seems the right way is form.cleaned_data.get('formfieldvalue')
or
form.cleaned_data[formfieldvalue']
if you don't want to use get
Re: Learn web development: Django Web Framework
#48Huh. Makes me miss php
Re: Learn web development: Django Web Framework
#49Earlier quoted context omitted.
Yeah, or another way of splitting up huge models files is to convert models from a module to a package by making a directory models and adding models/__init__.py, models/foo_models.py, models/bar_models.py then doing from .foo_models import * from .bar_models import * in your __init__.py
Separating models like this is a hint that you may need another app. It has happened numerous times with me now that my models.py gets large and unwieldy, I spends a hour breaking it all out and then I realise my one big God app needs to be 3 smaller ones.
Re: Learn web development: Django Web Framework
#50This is pretty fantastic. I was just thinking about diving into learning Django for an idea I want to build so this link is timely.