Mirco
but WHY?
def get_default(self): """ Returns the default value for this field. """ if self.has_default(): if callable(self.default): return self.default() return force_unicode(self.default, strings_only=True) if (not self.empty_strings_allowed or (self.null and not connection.features.interprets_empty_strings_as_nulls)): return None return "" this is what Django does under the hood so no exception should be raised
Luis
ok, i know it will work, but i thought it will work in shell too, at orm level
https://docs.djangoproject.com/el/2.1/ref/models/instances/#django.db.models.Model.full_clean
Luis
I think you should use full_clean before saving the instance
Mirco
wow i just want to paste same code
😂 I think because we like to know what Django really does under the hood after reading docs
Alexander
also may be you should not use forms at all and make forms on js side (use Vue.js, for example) + API (Django Rest Framework is the most popular choice here)
Александр
thanks @pyflare , @LuchoUY
Alexander
DRF Serializers may replace Django forms
Luis
thanks @pyflare , @LuchoUY
From docs Note that full_clean() will not be called automatically when you call your model’s save()method. You’ll need to call it manually when you want to run one-step model validation for your own manually created models
inchidi
Александр
what do you mean?
i mean, if i need to write a model field that rejects blank values by myself. haha, just wondering
inchidi
so you wanna create your own models.CharField(), models.IntegerField() etc everytime you start your project?
Александр
yes
Luis
i mean, if i need to write a model field that rejects blank values by myself. haha, just wondering
Just do not use model.objects.create Create an instance of your models and call full_clean method before calling save method. I experienced the same issue in 1.11 and full_clean do the job.
Luis
all right, I got it, thanks =) Django Tutorial is disappointing
Django is like strong vodka. Makes your pains easier, but simple stuff turns hard (like walk drunked)
Luis
My English grammar sucks hahaha
Александр
Mirco
Django is like strong vodka. Makes your pains easier, but simple stuff turns hard (like walk drunked)
mmm not completely agree with "simple stuff turns hard" but funny thought 😂
Luis
mmm not completely agree with "simple stuff turns hard" but funny thought 😂
I like DJango. It makes web development pretty simple and fast, but you should to know what is it doing behind the scenes.
Luis
It's these or just use WordPress hahahaha
Mirco
I like DJango. It makes web development pretty simple and fast, but you should to know what is it doing behind the scenes.
I think something looks hard just because lots of people wanna use Django without having a good knowledge of Python but if u used Django with a strong Python knowledge, especially OOP , you will find what framework offers to you easier obv it's just my pov
Luis
I think something looks hard just because lots of people wanna use Django without having a good knowledge of Python but if u used Django with a strong Python knowledge, especially OOP , you will find what framework offers to you easier obv it's just my pov
I'm agree! But it has these "details" like full_clean to force validation in new model's instances to avoid blank values, etc. Any way, I was joking about DJango and vodka... it's not personal haha
Anonymous
Does anybody have the VPS?
Mirco
Does anybody have the VPS?
I think nobody will give it for free
Anonymous
I have these models but when I want to add a food,categories of other restaurant are also showing up as a option,How can i make to show of only particular restaurant? Thanks https://dpaste.de/xvT5#L1
Anonymous
Filter by restaurant
Thanks you I will try your solution
Sh
Thanks you I will try your solution
yeah try it, good solution
Anonymous
Does anyone know how to implement jalali / Persian calendar? Do I need to do that with Django? What's the usual approach?
Anonymous
I mean maybe it's usual to convert dates in front end
Aston
hello world!
Anonymous
I want to set value of a field in a model using another field like this: (don't ask about why you do this, this is just a simple example) created = models.DateTimeField(auto_add_now=True) created_str = models.CharField(max_length=50) I want something like this: created_str = models.CharField(max_length=50, default=str(created)
Anonymous
well, it has to be asked... why? because... why do you want to do that if you already have the value in one field? nvm... you can override save() and do things there IG
Thank you, I'll try to do that I like to say why So many steps are omited for sake of simplicity There's this python package that converters Gregorian date to my local date
Anonymous
It does not have to be a specific date system Any solution for a calendar other than Gregorian would be my answer
Anonymous
Finally I did it with template filler and some conversions Turns out I didn't need to store local date and time. I think it's a better approach. Now database and model file remains intact
Anonymous
Good day guys, my team and i has been facing issues with aws since morning, we have been trying import ssl certificate to AWS, and its been telling us that we have gotten to the limit of certificates import, and we havent import any certificates, please what could be wrong?
Álex
This morning we've also had some issues and we realised that were because of the last release (yesterday) so when we built our containers with the latest version of Django some incompabilities came up. Take a look just in case...
Gursi........
K
LeoBellier
Hello guys, someone knows how I could do a many to one relation?
Guillermo
Guillermo
Thats just a ForeignKey
LeoBellier
Thank you dude, I was not sure
Anonymous
how to divide my api apps? i dont know how django rest works with urls. I want something like <project dir> <accounts> <api> <api app 1> <api app 2>
Gursi........
https://hastebin.com/ohekaketip.php
Gursi........
I want to print true only if no digit is there
cj
https://hastebin.com/ohekaketip.php
🤔 what is it doing here?
Charly
well seems to be python, invalid python but python
cj
I want to print true only if no digit is there
go to @Python group for that kind of questions
Anonymous
Pittsburgh any server virtual ( VPS) it?
Aadhi
Guys I am facing an issue while running my project. Edited features is not coming to my default port number. Every time I need to change the port number while running. Any Idea why it happens?
what did Google tell you?
that I should go to Hell
How to initialize object and make accessible everywhere in project/app directory
Mirco
How to initialize object and make accessible everywhere in project/app directory
What kind of object ? Try to explain better your context
Guillermo
How to initialize object and make accessible everywhere in project/app directory
you could use the database, an in-memory database like redis or memcached, I think your app's __init__.py could work too. You could also put it in your settings if its not going to be modified and if it does not depend on the database beign accesible...many options that depend on the nature of the object
What kind of object ? Try to explain better your context
Im using pure-python-adb library (android debug bridge), and there to start I need initialize client object: client = AdbClient(host="localhost", port="5037") So I need to initialize once and make accessible from everywhere to get devices
So you need to use client object into your views, right ?
yes, but i did initialized it in context_processors
Mirco
yes, but i did initialized it in context_processors
And ? Not working ? Anyway context_processors are for templating scope You could write a Middleware to include your client object into request
And ? Not working ? Anyway context_processors are for templating scope You could write a Middleware to include your client object into request
Working if I need to send something in view, but if I need to get instance of the client object(for now I tried to bind client to request.sessions) it not works
Mirco
Thanks
Yw 😊 Anyway for your case, if u wanna use that instance into every templates , I suggest you to work better on context_processor
Yw 😊 Anyway for your case, if u wanna use that instance into every templates , I suggest you to work better on context_processor
I'm already using it on context_processor to display in templates, but I need instance in code of Views
Try to write a custom middleware so can include your instance into request object
can u please provide me with an example of getting value that was set in responce middleware in view