These are chat archives for django/django

21st
Jul 2017
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 02:47
hey... can someone help me with DRF?
Roel
@roelzkie15
Jul 21 2017 05:47
@jlugao you can post your problem here
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:13
yoyoy
Hello people
I have a question.
a problem*
'''''''
{{ carousel.carousel_image_1.url }} doesnt print out the url for the image
but if I put it in a for loop in the template it does
the views are no different.
just templates
it doesn't seem like anybody else have this problem. at least using the keywords I used in google
any body have a slightest idea why this is?>
normally you would be able to just print out the value like that but this doesnt work without a for loop for some reason
Roel
@roelzkie15
Jul 21 2017 06:27
@YiiKuoChong may be caoursel is a list?
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:27
it isnt
I limit it to one model
now that you said it
Roel
@roelzkie15
Jul 21 2017 06:28
can you put your code so anyone can see?
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:28
I'll test it first.
Thank you
Roel
@roelzkie15
Jul 21 2017 06:28
maybe you can do this coursel.0.carousel_image_1.url?
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:29
.0.?
Roel
@roelzkie15
Jul 21 2017 06:29
you limit it to one model? i have a feeling that you still make it as a list
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:30
I am passing it as a string now instead
not string
oops
I remove the list now instead
one part works
the other I need to figure it out first
Roel
@roelzkie15
Jul 21 2017 06:31
write your code
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 06:31
I never obtained consent to show the code so I won't. The client probably don't care though.
right. I figured it out
Thanks
I thought it was something more complex. Turns out it was because it's a list.
carousel_objects = CarouselDisplayModel.objects.filter(carousel_display=1)
carousel_display is a BooleanField
I should use True right?
rigth
it works
Thank You @badcoder28
Roel
@roelzkie15
Jul 21 2017 07:07
@YiiKuoChong you can get a single instance of a model by CarouselDisplayModel.objects.get(carousel_display=1) .filter() returns a queryset which is list and .get() return an instance of a model.
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 07:07
@badcoder28 Thank you.
Roel
@roelzkie15
Jul 21 2017 07:07
happy coding
Ghost
@ghost~58e3220cd73408ce4f55e9fb
Jul 21 2017 07:08
happy coding
vegandoc66
@vegandoc66_twitter
Jul 21 2017 12:08
Greetings
Miracle Ayodele
@iammiracle
Jul 21 2017 18:28
hi guys, if anyone is online you can join treehouse live coding
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 18:41

I have 3 models (School, Program and Class)
School and Program have a m2m relationship
Class has foreign keys to both school and program
In my endpoint I want json data looking like this:
School
| Program
|
Class
I can get my head around nesting the serializers I just don't know how to filter the classes for that specific School inside of the program serializer.

In the Program serializer I call the Class serializer, however with this approach I'll get all the classes in the same program from every school. I want just the classes in this particular school. How should I do this?

@badcoder28 think you can help me out?
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 19:09
if someone teachs me how to filter one level I'll manage the other
matxpg
@matxpg
Jul 21 2017 19:37

Hi,
I need to learn how to integrate client-side interfaces into an existing django project which has a very well developed back-end. I have a question about django templating.

I see "{'front-end web framework'} Integration with Django", e.g. Bootstrap3 integration - https://github.com/dyve/django-bootstrap3

Is it possible to just write the front-end 'like normal' and somehow include it in the template for a page? i.e. Am I able to just include the front-end work I have already into a template, somehow, without having to convert it to the templating language with a library like the above bootstrap3 repo?

It's a bit confusing for me -- if I'm not clear on the question please let me know and I'll try to clarify things!

João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 19:43
@matxpg you can write the template on top of the html you already have
you can get the frontend framework from a CDN as you normally would
and you don't have to use anything like django-bootstrap3
have you seen django tutorials? I think that it will be pretty clear how to create the templates and use template tags. If you are doing just a redesign you probabbly can leverage the templates that are already written
matxpg
@matxpg
Jul 21 2017 19:47
@jlugao Okay, thanks! Followup: I've used a module bundler (webpack) and babel (so I can write in ES6). Is it as simple as building this separate from the Django project and then including the static bundle.js in the template?
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 19:48
are you using a javascript framework?
you can compile things with npm build and use the bundled file to help you build the templates
matxpg
@matxpg
Jul 21 2017 19:49
The client-side interface I've used makes use of uikit, d3js, ...
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 19:49
and the javascript parts will go into the static files
matxpg
@matxpg
Jul 21 2017 19:50
Okay. That makes a lot more sense -- thanks a bunch!
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 19:50
you will have some work making any async part work... and d3js also... but there are lots of good tutorials out there
João Ricardo Lhullier Lugão
@jlugao
Jul 21 2017 20:38
I added a bit of code to see if anyone can help me https://redd.it/6oqj1b