These are chat archives for django/django

19th
Aug 2016
Andrew Backer
@awbacker
Aug 19 2016 03:44
damn, isn't there an angular-js support group somewhere
wqhhust
@wqhhust
Aug 19 2016 08:33
In the model, I defined the following
def __str__(self):
    return self.last_bidding_time + self.school
last_bidding_time is date, so it throws error, but how to format it as string?
last_bidding_time = models.DateTimeField(blank=True, null=True)
MinJae Kwon
@mingrammer
Aug 19 2016 08:35
use strftime function in time package
Igor Malinov
@malinich
Aug 19 2016 08:36
unsupported operand type(s) for +: 'datetime.datetime' and 'str'
MinJae Kwon
@mingrammer
Aug 19 2016 08:36
import time
...
return time.strftime([time format], time) + self.school
wqhhust
@wqhhust
Aug 19 2016 08:37
great, thx
Igor Malinov
@malinich
Aug 19 2016 08:37
you need covert you datetime to str as @mingrammer propose
wqhhust
@wqhhust
Aug 19 2016 08:45
the document after good said we need to use datetime and don't use time. then I tried to use
datetime.datetime.strftime(self.last_bidding_time,%c)
but it failed
If use datetime, then what's the code to use?
Igor Malinov
@malinich
Aug 19 2016 08:47
datetime.datetime.strftime(date, '%Y')
i don't know why datetime.datetime.strftime(self.last_bidding_time,%c) is fail , it work to me
self.school - may be not str?
wqhhust
@wqhhust
Aug 19 2016 08:51
This is the error message
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/data/django/mysite/polls/models.py", line 61
return datetime.datetime.strftime(self.last_bidding_time,%c)
^
SyntaxError: invalid syntax
sorry, I see, I didn't put %c into '%c'
Igor Malinov
@malinich
Aug 19 2016 08:52
)
wqhhust
@wqhhust
Aug 19 2016 08:54
Then how to handle null for the time column?
TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'NoneType'
some rows has that column as none
looks like strftime doesn't work on null value
Oleg Serbokryl
@Krokop
Aug 19 2016 08:55
@wqhhust
if date:
    datetime.datetime.strftime(date, '%Y’)
wqhhust
@wqhhust
Aug 19 2016 08:57
oh, how stupid I am!
wqhhust
@wqhhust
Aug 19 2016 09:13
I have the code
def __str__(self):
    if self.created_time is None:
       return self.school
    else:
       return datetime.datetime.strftime(self.created_time,'%c') + self.school
but it still throw the error of
File "/data/django/mysite/polls/models.py", line 65, in str
return datetime.datetime.strftime(self.created_time,'%c') + self.school
TypeError: Can't convert 'NoneType' object to str implicitly
Oleg Serbokryl
@Krokop
Aug 19 2016 09:14
maybe self.school is None too?
wqhhust
@wqhhust
Aug 19 2016 09:16
yes, you are correct, it's so hard to handle null.
Oleg Serbokryl
@Krokop
Aug 19 2016 09:17
you can str(self.school)
wqhhust
@wqhhust
Aug 19 2016 09:19
great, it works:)
Oleg Serbokryl
@Krokop
Aug 19 2016 09:21
but str(None) return ’None’
it’s ok for you?
wqhhust
@wqhhust
Aug 19 2016 09:26
it works great :)
Another question, when using the model, I know how to sort the data by adding the ordering to the Meta class inside the model, but can we do filter?
I am using the admin to manager the table, but don't want to show some records whose school is empty.
list_filter = ('is_staff', 'company')
wqhhust
@wqhhust
Aug 19 2016 09:36
That's helpful, but I am pretty new to django, where should I put these code? Currently the class I am working on is something like class Bidding(models.Model):
But the code you show is class PersonAdmin(admin.ModelAdmin): where should put the code?
in the admin.py?
Oleg Serbokryl
@Krokop
Aug 19 2016 09:37
yeap
wqhhust
@wqhhust
Aug 19 2016 09:44
In the admin.py, I have

from django.contrib import admin

from .models import Bidding
admin.site.register(Bidding)

class BiddingAdmin(admin.ModelAdmin):
list_filter = ('school',)

is that correct? but I didn't see any filter on the web page
Oleg Serbokryl
@Krokop
Aug 19 2016 09:45
admin.site.register(Bidding, BiddingAdmin)
wqhhust
@wqhhust
Aug 19 2016 09:46
cool, I see the filter now.:)
Oleg Serbokryl
@Krokop
Aug 19 2016 09:46
:+1:
Lucas Georges Helal
@LucasHelal
Aug 19 2016 17:47

Hey guys, someone uses Docker in their development?

I am searching any material or dockerfile using python 3 and django. Do you have something to pass me?
thank you.

waspinator
@waspinator
Aug 19 2016 19:13
@LucasHelal
To get started try these docker commands
docker run --rm -it -v $(pwd)/django:/code django:1.10 django-admin startproject my_project_name /code
docker run --rm -it -v $(pwd)/django:/code -p 8000:8000 django:1.10 bash
and then cd into code and run python manage.py runserver 0.0.0.0:8000