These are chat archives for django/django

11th
Aug 2016
leeeandroo
@leeeandroo
Aug 11 2016 00:47
Hello everyone,
I`m looking for a best way to do a websocket comunication with django via API using DRF. Is still the better choice build a websocket server using Tornado? How can I send message to client when a new model is saved on django?
Any tips to start develop this?
Oclay
@Oclay2_twitter
Aug 11 2016 01:05
@leeeandroo well, you can use signals
please take a look at django-channels
mark
@thenewidealism_twitter
Aug 11 2016 05:31
could i get some help displaying the attacehed images to the post? for some reason, the image won’t show. http://192.241.153.25:8000/#/post/Images i loaded images using the traditional img tag
MinJae Kwon
@mingrammer
Aug 11 2016 05:34
src is empty
mark
@thenewidealism_twitter
Aug 11 2016 05:34
yes
that’s weird.
MinJae Kwon
@mingrammer
Aug 11 2016 05:35
show your code
mark
@thenewidealism_twitter
Aug 11 2016 05:35
sec
          <div class="post_detail" style="overflow-wrap: break-word;">{{post.content}}<br>
                    <img src="{{ post.image }}"></div>
rest of the front end code
i think though it’s a problem in the backend. if you need further information, just request the code.
MinJae Kwon
@mingrammer
Aug 11 2016 05:42
what's type of post.image?
mark
@thenewidealism_twitter
Aug 11 2016 05:42
i believe it’s json
um wait.
for some reason the image is null
sec...
okay. chnage of the question .
mark
@thenewidealism_twitter
Aug 11 2016 05:47
so the image appears on the detail page just fine : http://192.241.153.25:8000/#/post/images2
but i would like to insert this image as a background image to the list page
right now the .post_wrapper is colored grey
MinJae Kwon
@mingrammer
Aug 11 2016 05:48
yes i see
mark
@thenewidealism_twitter
Aug 11 2016 05:49
but is there away i can replace the background color with the image attached to the post?
i’ve already tried few ways, but doesn’t seem to be appearing for some reason.
MinJae Kwon
@mingrammer
Aug 11 2016 05:50
I don't know angular.js. but you can insert image url to style attribute.
like this <a style="background-image: [image url]">blah</a>
mark
@thenewidealism_twitter
Aug 11 2016 05:50
i think i tried that but sec
<div class="well" style="background-image:url('{{ post.image }}')">
this doesn’t work.
This message was deleted
MinJae Kwon
@mingrammer
Aug 11 2016 05:59
how get the post value? api call?
mark
@thenewidealism_twitter
Aug 11 2016 06:00
yes.
it’s loaded the same way in the post detail page.
like, <img src=“ {{ post.image }}”>
would work, but not the way above.
oh wait.
it doesn’t work either.
maybe it’s the angular js missing out the functon.
MinJae Kwon
@mingrammer
Aug 11 2016 06:02
post.[attributes] values is correct in api response?
include image
mark
@thenewidealism_twitter
Aug 11 2016 06:03
i think so, but im not absolutely sure. cause im not the one who wrote the angular script
MinJae Kwon
@mingrammer
Aug 11 2016 06:03
check the api response before rendering
mark
@thenewidealism_twitter
Aug 11 2016 06:03
sec
MinJae Kwon
@mingrammer
Aug 11 2016 06:04
api testing is essential
mark
@thenewidealism_twitter
Aug 11 2016 06:05
how do i check it?
where do i put console.log(response); ?
MinJae Kwon
@mingrammer
Aug 11 2016 06:06
api testing tools, curl command, ...
mark
@thenewidealism_twitter
Aug 11 2016 06:07
i mean the image is inside the API
it’s just the image tag not working probably.
MinJae Kwon
@mingrammer
Aug 11 2016 06:11
image value seems like correct value ..
mark
@thenewidealism_twitter
Aug 11 2016 06:11
yes.
weird.
MinJae Kwon
@mingrammer
Aug 11 2016 06:11
(yes, that's one of the api testing method)
hmm .. could you test the api on plain html rendering? not angular.js (I don't know this)
mark
@thenewidealism_twitter
Aug 11 2016 06:15
that would be pointless because either way i need to use angular js for the rendering only because everything’s written in angular.
but anyways,
thanks for the help. i guess i will ask this on the #angular channel see if they know something about this.
this seems more like a frontend than backened.
MinJae Kwon
@mingrammer
Aug 11 2016 06:19
ok, I hope good news
Lioman
@lioman
Aug 11 2016 07:41
@thenewidealism_twitter do you use websyou can include a image by using ng-src= https://docs.angularjs.org/api/ng/directive/ngSrc#!
mark
@thenewidealism_twitter
Aug 11 2016 07:42
yes but i have to use style=“background-image"
which doesn’t take src as an attribute
Lioman
@lioman
Aug 11 2016 07:48
This message was deleted

Try This:

<div class="well" ng-style="myBackground">

in controller

$scope.myBackground = {
     background: url(urlToImage) // must be set after api call
};
mark
@thenewidealism_twitter
Aug 11 2016 07:56
thanks. but not working/
i maybe have short knowledge.
RompePC
@RompePC
Aug 11 2016 08:16
Anyone could throw ideas for a coercing to Unicode: need string or buffer, NoneType found when using admin panel? And no, the code is the same for other models and doesn't throw errors, its weird. The error is throwed at {% if field|is_checkbox and form_show_labels %}, I think that is from crispy_forms.
Lioman
@lioman
Aug 11 2016 08:44

@thenewidealism_twitter It is working like expected:

$http.get('view1/response.json' //your url here
        ).then(function (response) {
            $scope.viewStyle = {
                background: 'url('+response.data.image+')'
            };

and then you have to use ng-style=viewStyle

mark
@thenewidealism_twitter
Aug 11 2016 08:44
i’ll give it one more try thanks.
it’s throwing missing ) error
angular.module('app')
.controller('profile_image', ['$scope','$http', function($scope, $http) {//this one controller is new

  $http({
    url: '/api/users/profile/',
    method: "GET",
    params: {username: 'lifeto'}
}).then(function successCallback(response) {
    console.log("Profile Image");
    console.log(response);
    $scope.lifeto_img = response.data;
}, function errorCallback(response) {
    console.log("Error fetching profile image!");
});

$http.get('/api/posts/').then(function (response) {
            $scope.viewStyle = {
                background: 'url('+response.data.image+')'
            };

}]);
Lioman
@lioman
Aug 11 2016 08:51
because there is missing a }) after $scope.viewStyle = { background: 'url('+response.data.image+')' };
I forgot to copy a line - sorry
mark
@thenewidealism_twitter
Aug 11 2016 08:54
hmm okay
but
it’s throwing one more errror
unexpected token .
angular.module('app')
.controller('profile_image', ['$scope','$http', function($scope, $http) {//this one controller is new

  $http({
    url: '/api/users/profile/',
    method: "GET",
    params: {username: 'lifeto'}
}).then(function successCallback(response) {
    console.log("Profile Image");
    console.log(response);
    $scope.lifeto_img = response.data;
}, function errorCallback(response) {
    console.log("Error fetching profile image!");
});

$http.get('/api/posts/').then(function (response) {
            $scope.viewStyle = {
                background: 'url('+response.data.image+')'
            };
});

}]);




.directive('whenScrolled', function($document) {//another directive
        return function(scope, elm, attr) {
            var raw = elm[0];

             $document.bind('scroll', function() {
                if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
                    scope.$apply(attr.whenScrolled);
                }
            });
        };
    })
i forgot how to solve this error.. sorry
MinJae Kwon
@mingrammer
Aug 11 2016 08:58
there is nothing before .directive?
mark
@thenewidealism_twitter
Aug 11 2016 09:01
nope.
Lioman
@lioman
Aug 11 2016 09:02
You must not end your controller with ';' if you want to add something else.
mark
@thenewidealism_twitter
Aug 11 2016 09:02
oh. mybad
i guess it’s working except that i seem to get “undefined” url for the image
Lioman
@lioman
Aug 11 2016 09:08
It is because you are calling ap/posts and not api/posts/NAME
MinJae Kwon
@mingrammer
Aug 11 2016 09:10
that's right
mark
@thenewidealism_twitter
Aug 11 2016 09:10
sec.
is there a way i can set the url in a way that it detects automatically? or do i have to do that manually?
Lioman
@lioman
Aug 11 2016 09:13
What do you mean by detect automaticcally?
mark
@thenewidealism_twitter
Aug 11 2016 09:13
each of the posts in the django app has its own unique ID (name)
you just said that im missing the name in the url
MinJae Kwon
@mingrammer
Aug 11 2016 09:14
Do you want to list the all posts of a user?
mark
@thenewidealism_twitter
Aug 11 2016 09:14
sorry i didn’t get that
come again?
i basically just want to display the attached images to the post.
MinJae Kwon
@mingrammer
Aug 11 2016 09:17
Yes i know, but what is the intent of the aboce code?
mark
@thenewidealism_twitter
Aug 11 2016 09:17
oh.
sec. i updated the code.
(function() {
  angular.module('app', ['ngRoute', 'ngResource'])
.controller('FilesListCtrl', ['$scope','$http', function($scope, $http) {//this one controller is new

  $http.get('/api/posts/').then(function (response) {
              $scope.viewStyle = {
                  background: 'url('+response.data.image+')'
              };
  });
Lioman
@lioman
Aug 11 2016 09:17
you are calling 'api/posts/' to get a list of all posts, but there is no image field set. Tha API return it if you call a single post like api/posts/test7
mark
@thenewidealism_twitter
Aug 11 2016 09:17
you can ignore the code above
@lioman yep. so i figure in this case i would have to include each and every name of the post inside that url
i was merely wondering if there is away i can avoid my self having to do that
MinJae Kwon
@mingrammer
Aug 11 2016 09:21
response.data is about every posts. but image attribute is in only a post data. right? then response.data.image is always undefined.
show the response of /api/posts/ and check the attributes
Lioman
@lioman
Aug 11 2016 09:22
@mingrammer it is undefined not null
MinJae Kwon
@mingrammer
Aug 11 2016 09:22
ah, sorry for that
yes, undefined
fix that
mark
@thenewidealism_twitter
Aug 11 2016 09:25
hmm
MinJae Kwon
@mingrammer
Aug 11 2016 09:25
show /api/posts/ response struct
mark
@thenewidealism_twitter
Aug 11 2016 09:25
im not sure if im getting it right but okay
the image seems to be loading fine. thanks guys for the help.
MinJae Kwon
@mingrammer
Aug 11 2016 09:27
if response data like this posts : [{'image': 'urlForImage'}]
you can get every image urls using for statement
var posts = response.data.posts this get the every posts list
then for (var i = 0; i < posts.length; i++){ setting background image process }
mark
@thenewidealism_twitter
Aug 11 2016 09:31
seems too complicate for me to comprehend.
:P
but thanks for the tip,
i will use it when it becomes relevant to my knowledge of angular
MinJae Kwon
@mingrammer
Aug 11 2016 09:32
it's not about angular, but api
mark
@thenewidealism_twitter
Aug 11 2016 09:32
oh okay.
MinJae Kwon
@mingrammer
Aug 11 2016 09:33
there is no about image url. so you could call each post url in for statement. also, you can add 'image_url' like attribute to every result entry and use the above method (for (var i = 0...))
mark
@thenewidealism_twitter
Aug 11 2016 09:35
okay. i will keep that in mind.. right now i can’t handle modifying the serializers.py and views.py for the Django rest framework.
perhpas i can understand it better when i revisit the issue next time.
MinJae Kwon
@mingrammer
Aug 11 2016 09:36
ok, then you should call each post api in for statement
ye.
Jambari
@jambari
Aug 11 2016 10:40
Hi.. what is the difference between Geodjango and google Map API?
Daniel Spajic
@dspacejs
Aug 11 2016 11:42
howdy y'all
it seems like this is way less active than IRC
i wish it was more active :P because i think this is better than IRC
mark
@thenewidealism_twitter
Aug 11 2016 12:00
are you on the freenode.net?
@cannatown
Cephlin
@Cephlin
Aug 11 2016 14:05

Hi all, I'm experiencing some difficulty changing one of my models to extend models.Model instead of another custom model I made. I can makemigrations without any issues like so:

Migrations for 'contact':
  0033_auto_20160811_1401.py:
    - Remove field templatecampaignemail_ptr from campaign
    - Add field id to campaign

It's only when I try to migrate them that I hit the following errors:

django.db.utils.ProgrammingError: column "templatecampaignemail_ptr_id" of relation "contact_campaign" does not exist

Does anyone have any ideas on this?

Cephlin
@Cephlin
Aug 11 2016 14:25
Ahh, I don't think it's possible to generate inheritance changes it seems
Lucas Georges Helal
@LucasHelal
Aug 11 2016 19:27

Hello Guys, I'm making the implementation of my application on AWS , would like some tips if possible , can send me some tutorial? I have given a good deal on the internet.

I'm using an instance in AWS free . My Database is with PostgreSQL. I'm using Python3 , gunicorn and nginx ( did NOT work yet. )