These are chat archives for django/django

6th
Dec 2017
MilanRgm
@MilanRgm
Dec 06 2017 01:42
@elcolie No problem. Thanks anyway for your consideration
:]
@elcolie
Dec 06 2017 02:38
@int-elligentSam https://www.youtube.com/channel/UCWEHue8kksIaktO8KTTN_zg
I started from here. It is a good one.
Raphael
@Raphael7788
Dec 06 2017 04:42
@elcolie let me just send you direct message, please check
:]
@elcolie
Dec 06 2017 06:22
@vin7788 Done
Luke-VideoLibre
@LukeVideo
Dec 06 2017 09:20
@int-elligentSam official documentation tutorial is a good start. Then there a couple of good youtube channels that can be interresting.
https://www.youtube.com/user/Max204204204
Is nice also for beggining
And also you can get the coding entrepreneurs course on udemy for free if you want all the material and links and chapters to follow allong.
MilanRgm
@MilanRgm
Dec 06 2017 11:57
@elcolie Thanks . That is what I was struggling to solve.
I have marked it as solved . I appreciate your kindness, skill and healthy character to help other
:]
@elcolie
Dec 06 2017 12:07
@MilanRgm Glad I am be able to help :D
MilanRgm
@MilanRgm
Dec 06 2017 12:38
:+1:
cubocsj
@cubocsj
Dec 06 2017 13:07
Hi all, I have a question. Is there a good way of storing / adding data that doesn't require a model. Things like a logo, an address, vat number etc, that just needs to queried to a template. But still editable in the admin? Like with data files in Hugo and Jekyll? Thanks.
MilanRgm
@MilanRgm
Dec 06 2017 13:22

when i enter this url http://localhost:8000/category/bedroom-items/almirah/2-piece-almirah whose route is configured as following

url(r'^category/(?P<hierarchy>.+)/', views.show_product_on_category, name='product-category'),

then in views

def show_product_on_category(request, hierarchy=None):
    print('hierarchy', hierarchy) # this prints hierarchy bedroom-items/almirah

Does not this should print hierarchy bedroom-items/almirah/2-piece-almirah?

why removing / like the following

url(r'^category/(?P<hierarchy>.+)/'

then prints the hierarchy bedroom-items/almirah/2-piece-almirah. I am very curios to understand why this works and not the other?

Luke-VideoLibre
@LukeVideo
Dec 06 2017 14:16
Is there an easy way to check if on file upload a file name has spaces and avoid making it break whole app??
Is there a django feature to validate such case?
Craig Labenz
@craiglabenz
Dec 06 2017 14:47
@MilanRgm You're saying that when you remove the trailing slash from your URL conf, it behaves as expected?
Luke-VideoLibre
@LukeVideo
Dec 06 2017 15:25
I have a Person model with
class Person(models.Model):
    # Create relationship (don't inherit from User!)
    user = models.OneToOneField(User)
    nickname = models.CharField(max_length=42)
I manage to get the user with request.user. However i can't figure out how to get the nickname... Any help?

i get

 AttributeError: 'User' object has no attribute 'Person'
AttributeError: 'User' object has no attribute 'nickname'

when trying in my view

            person = request.user
            print(person.nickname)

or

            person = request.user.Person
            print(person)
Luke-VideoLibre
@LukeVideo
Dec 06 2017 15:47
ok its person = request.user.person no P just p
right?
:]
@elcolie
Dec 06 2017 15:53
@cubocsj No
@LukeVideo You can. In case you use django template. It is form validation. On the other case like Django REST you have to use serializer validator
Luke-VideoLibre
@LukeVideo
Dec 06 2017 15:56
@elcolie Okay !
:]
@elcolie
Dec 06 2017 15:57
@LukeVideo But normally file name contains spaces is not a problem in Django. I have never found an issue about it.
Luke-VideoLibre
@LukeVideo
Dec 06 2017 15:58
Well i have a filefield and if i try to upload some file with spaces they don't get escaped and probably because i'm on linux it fails.
Hmm...
It might be accents.
spaces are replaced with underscores....
And test file.txt works fine. but Capture d'écran de 2017-11-17 11-24-59.png fails
:]
@elcolie
Dec 06 2017 16:03

@LukeVideo In order to use reverse relation. You are almost there. Use this
Let me define reverse relation in this way
user = models.OneToOneField(User, related_name='person')
Explicitly define the keyword is prefered here for sake of clarity

person = requuest.user.person
nickname = person.nickname

But in short you can simply write request.user.person.nickname
Do not be afraid to has long dot. It works. Normally import pdb; pdb.set_trace() I suggest next time on this issue try pdb It will save your time a lot.

Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:03
@elcolie Nice
:]
@elcolie
Dec 06 2017 16:05
@LukeVideo New information for me. I used to deal with Japanese encoding. But no problem. It might be frontend engineer convert the filename before POST them to me already(IMO)
@LukeVideo Try upload file with filename written in utf8 and space in utf8. I don't believe Django rejects it
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:08
I'm just guessing. I picked a random file in my images folder and that's also where gnome sends screenshots with this awfull naming. Spaces,accents, dashes. I'll have to take the time to fix this.
:]
@elcolie
Dec 06 2017 16:08
What is the error mesagges
Can you share your code?
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:09
with  open(document, 'rb') as afile:
FileNotFoundError: [Errno 2] No such file or directory: "/home/lukevideo/.../media/documents/Capture d'écran de 2017-11-17 11-24-59.png"
:]
@elcolie
Dec 06 2017 16:09
Aha it is not a Django issue man.
The actual filename is Capture\ d'écran\ de\ 2017-11-17 11-24-59.png
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:10
never said so !
:]
@elcolie
Dec 06 2017 16:11
Oh sorry. I though that way ;p
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:11
teh file name is Capture_décran_de_2017-12-05_17-34-36_qq1fG1d.png
:]
@elcolie
Dec 06 2017 16:11
Looks normal
Is it work?
Try change your browser from FF to Chrome
Or update them
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:12
avoid making it break whole app. Might of sounded a little negative on django...
It's not the browser, the error is in the django logs
:]
@elcolie
Dec 06 2017 16:13
Are you using form to do an uploading?
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:13
Yes
:]
@elcolie
Dec 06 2017 16:13
Oh sure of course. It is only one way. I usually do backend with REST.
I will use Django2.0 because it is brand new here. And try upload the file like yours @LukeVideo
Could you please send me that file to my email?
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:15
sure
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:15
@elcolie got it
:]
@elcolie
Dec 06 2017 16:17
It takes time about 30 minutes I am messing with boilerplate. Cookiecutter is behind Django2.0 :(
Luke-VideoLibre
@LukeVideo
Dec 06 2017 16:20
Is 1.11 really over now?
I guess i should migrate now, my project is still very young.
1.11 is doing fine as it's an LTS, silly me!
:]
@elcolie
Dec 06 2017 16:26
My project is under developing then version will be upgraded if it has no any difficulties like dependencies lock.
:]
@elcolie
Dec 06 2017 17:08
@LukeVideo I confirm on GNU/Linux Debian Stretch Django2 Python3.6.3 can upload your file
I will upload my source at my repo. One moment
:]
@elcolie
Dec 06 2017 17:16
git@github.com:elcolie/show-upfile.git
@LukeVideo
emihir0
@emihir0
Dec 06 2017 17:26
Is there some guide out there which shows (ideally step by step with explanation) how to migrate an existing mysql database of the project into a fresh postgresql database?
Assume you database schema is identical
Luke-VideoLibre
@LukeVideo
Dec 06 2017 19:41
@elcolie yes sure. But can you sace(commit= fasle and read it as file with python in your views? I'll send you more details tomorrow !
I'll also consider launching from different console. I'm using the terminal in atom that might be causing the non UTF-8 exception.
Carlos Jose Fragoso Santoni
@cjfragoso
Dec 06 2017 23:39
hi
anyone familiar with webapp2?