inchidi
maybe the js raise an error
George
</footer> {{ form.media.js }} </body> </html>
George
only favicon error
George
maybe it doesn't support django 2.1
inchidi
did the js fully loaded? try follow url generated in your page
George
nope
George
there is no js :(
George
why doesn't it load the js
inchidi
then 9/10 thats the problem. a sec, let me check the doc
George
omfg
George
my theory is that i was overwriting form in the views but i put it a different name
George
Add the CSS to the head of your Django template: {{ form.media.css }} Add the JavaScript to the end of the body of your Django template: {{ form.media.js }}
George
neither the css or the js appear
George
omg
George
but, really, i have to load this for any form?
inchidi
but, really, i have to load this for any form?
yeah, since its the dependecy of the select generated
George
ooohh
George
what a bullshit
George
IT LOADS
George
THANK YOU @Inchidi
inchidi
what a bullshit
well thats how js works
inchidi
alright you're welcome
George
yes but it's not clear
George
in the docs
George
also it's too small the generated object
inchidi
looks like css thingy. did something overwrite the css or the css fail to load?
George
yes, maybe
George
i have to see, hmm
inchidi
or maybe you put the form.as_table at too small div
George
:/
George
i think i didn't put a limit
George
width: auto;
inchidi
got it working using a json dump 🙂
if its rest api project, i would like to suggest you using drf. it will help you so much
inchidi
width: auto;
try put outside anything like: <body>{{ form.as_table }}..</body> and see if it load properly. if yes, then outer element too small, if not, then the element itself have too small size.
George
i have it in another div and it expands when selected
inchidi
add __str__ to your model tho
Ronald
if its rest api project, i would like to suggest you using drf. it will help you so much
Thanks man. This is simply something I needed for for JavaScript ajax call purposes (using ChartJS). I do however think I'll add DRF in the near future. 😉
George
add __str__ to your model tho
there is a problem, i need the object to print depending on the field
inchidi
there is a problem, i need the object to print depending on the field
then def __str__(self): return str(self.field_model_name) it
George
oh really?
inchidi
yeah you can do that to your Model
George
if my model is FailureType would it be str(self.field_FailureType)
inchidi
no it will be str(self.spectrum)
George
hmmmmmm
George
but the problem is that i have to filter each one, its strange but it makes sense for me
inchidi
then def __str__(self): return str(self.field_model_name) it
you put this in your FailureType Model btw
George
Yes yes, i know but hum
George
i got another problem, the queryset is being ignored
inchidi
but the problem is that i have to filter each one, its strange but it makes sense for me
it wont effect the filter, just how the object instance represented
George
right
George
i mean, my queryset filters and gets 3 elements but i get 6
inchidi
i mean, my queryset filters and gets 3 elements but i get 6
FailureType.objects.filter(spectrum='infrared') is your QuesySet right?
George
yes
inchidi
thats weird but ig its not about select2 anymore since the queryset handled by ModelChoicefield
George
class MyWidget(ModelSelect2Widget): queryset=FailureType.objects.filter(spectrum = 'infrared').order_by('id') search_fields = [ 'kind__icontains' ] class FailureForm(forms.ModelForm): class Meta: model = FailureType fields = ['kind'] widgets = { 'kind': MyWidget, }
George
i think i'm gonna dump django-select2, it's a waste of time
inchidi
i think i'm gonna dump django-select2, it's a waste of time
and implement select2 by yourself. i want to suggest you that too a moment ago lol
George
i already did my implementation and works
George
but i was trying something more pythonic
George
i already made a dependent dropdown and it's working but only with custom jquery and shit, if anyone needs it, just ask
George
i think it's somewhat hardcoded but it works
inchidi
but i was trying something more pythonic
explicitly divide your front end and backend is kinda pythonic imho
George
explicitly divide your front end and backend is kinda pythonic imho
haha, yes, but i don't want to make a new piece of html whenever i need another dropdown
George
i am going to rest, thank you as always inchidi
inchidi
okay you're welcome
George
English
Anonymous
how do I access an object related to another related object? I have a Question class, a Comment, and a Reply. Comment is with an FK for Question, and Replu is with an FK for Comment. I can access the comments using Question.comment.all, but I can not access the answers using Question.comment.reply.all, it is giving error '' RelatedManager 'object has no attribute' replies' "in my view. app: https://github.com/marcoscoder/vesttest/tree/master/questoes
Combot
Marcos (0) has increased reputation of Mirco (7)
Mirco
Ty
Yw 😀
Mirco
Ty
Or this one https://stackoverflow.com/questions/15553167/querying-models-in-django-two-levels-deep
Anonymous
in the stackoverflow examples, the query is filtered, I want to simply retrieve all objects in Question> Comment> Reply