These are chat archives for django/django

10th
Jun 2016
lego
@legobillyjoe
Jun 10 2016 10:39

Question

In Django tutorial part 2 we are defining a custom method was_published_recently(self): , which look like this:

class Question(models.Model):
    # ...
    def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

What is self in it?

Thanks.

toddler
@bishal1995
Jun 10 2016 11:28
@legobillyjoe self refers to its own object
Filip Figiel
@megapctr
Jun 10 2016 11:48
@legobillyjoe self is equivalint of implicit this in other languages
AntonTokar
@AntonTokar
Jun 10 2016 14:10
where can I better learn Python independently and have first practice?
Roman
@roman-oxenuk
Jun 10 2016 14:35
@AntonTokar not sure to undersand your question, but I'll try to answer.
Reading books by Mark Lutz is a really good way to better learn Python.
And for first practice I'll suggest you to build your own pet-project.
Filip Figiel
@megapctr
Jun 10 2016 14:42
@AntonTokar for me, learning python was all about starting iPython and playing with it to discover how stuff works
you have tab completion, documentation (type in list.sort?) and lots of other stuff that makes discovering language a breeze
AntonTokar
@AntonTokar
Jun 10 2016 14:44
@megapctr thanks
@roman-oxenuk thanks
Joseph Muli
@josephmuli
Jun 10 2016 14:49
thanks @mnazim
deniskrishna
@deniskrishna
Jun 10 2016 15:22
hi there! could somebody help me please, there is an easy way to build a queryset from objects, returning from create() method, and then serialize this queryset. Without hitting db too much.
i have smth like this:
for  obj in data:
    newmodel = mymodel.objects.create(**obj)
# ..
#..
serializer = serializer(queryset, many=True)
return Response(serializer.data)
Patrick Harding
@senorpatricio
Jun 10 2016 15:27
AntonTokar
@AntonTokar
Jun 10 2016 15:30
@senorpatricio do u think it better way than Mark Lutz "Learning Python"?
Patrick Harding
@senorpatricio
Jun 10 2016 15:31
@AntonTokar not better, just another way to learn. I liked the approach in “learning python the hard way"
AntonTokar
@AntonTokar
Jun 10 2016 15:31
@senorpatricio thanks for your advice
Ashish Pahwa
@ashishpahwa7
Jun 10 2016 17:39
Hello , I was trying to learn about social auth(fb specifically) but most of the tutorials out there doesn't work well with version 1.9 . Could someone help pls?
Patrick Harding
@senorpatricio
Jun 10 2016 18:05
@ashishpahwa7 I’m seeing this one work with django 1.9: https://realpython.com/blog/python/adding-social-authentication-to-django/
Filip Figiel
@megapctr
Jun 10 2016 18:12
@deniskrishna I think there's bulk_create method
or something like that
look up the docs
Derrick Yoo
@derrickyoo
Jun 10 2016 22:39
If I am creating a reusable Polls app that requires jQuery as well as other 3rd party js libs, where would I place those dependencies in order for this app to be reusable in another Django project that does not have said 3rd party js libs installed? Do I package the app with the full libs in polls/static/js? Is there a better practice for shipping reusable Django apps that depend on js libs?
Patrick Harding
@senorpatricio
Jun 10 2016 22:41
@derrickyoo if you have a cdn link in your base.html you will not need to package them
That’s one way to do it.
Derrick Yoo
@derrickyoo
Jun 10 2016 22:45
@senorpatricio I see, that makes sense. I was trying to find a way to make it easier for other users who pip intall this app to not have to worry about including it themselves. But, I could just put it in the README that this app requires specific libs. Would this be a better practice? Thanks
Patrick Harding
@senorpatricio
Jun 10 2016 22:47
yes. that is a good practice also.
Derrick Yoo
@derrickyoo
Jun 10 2016 22:47
I would need to research this, but perhaps include a bower file in my polls app.