iNcAeLuM
is this correct?
iNcAeLuM
but for what is created var for?
Mirco
Docs explains it so well
Anyway if Django finds matches, it will use defaults to update instance otherwise Django creates new one with first_name and last_name specified ( not defaults )
Anonymous
iNcAeLuM
Mirco
iNcAeLuM
obj, created=.....
iNcAeLuM
created is nmot used
Mirco
Obj is for instance, created for True/False it depends on the result of the query
Mirco
created is True if obj does not exist
Mirco
False if exists and Django updates the instance
iNcAeLuM
Mirco
Mirco
It's simple
Mirco
Mirco
Otherwise, created will be True and you will have a new instance with John Lennon as first and last name
Mirco
Enough clear ? 😊
iNcAeLuM
Mirco
iNcAeLuM
Mirco
let me take a sec to undestand what are u sayin
Let's say you have a red apple, but it's not on the tree yet
When you ask Django to update or create an apple with red as color parameter , Django will tell you : hey I didn't find any apple on the tree , so I will create one for you with color equals to red
Mirco
Now you have a red apple on the tree 😁
Ask again Django to create or update, if it's on the tree change its color to yellow ( specified into defaults )
Django will tell you: hey, I've found one so I will change its color to yellow , I already know what color by taking it from defaults
Now you have an "updated" apple 😊
Mirco
Is it now clear ? 😁
iNcAeLuM
lets say i have this dict:
{"match":"barcelona - Madrid",
"time_match": "any_time",
"goal keeper":"anyone",
.
.
.
}
so i want if match is the same then update all fields, if not then create a new one
Mirco
So your dict will go inside defaults dict
iNcAeLuM
iNcAeLuM
obj, created = match_comming.objects.update_or_create(
match="barcelona - Madrid",
defaults={mydict},
)
iNcAeLuM
if matches then update all other fields
iNcAeLuM
if not then create new one with all dict filds
iNcAeLuM
?
Mirco
Defaults is for updating
iNcAeLuM
it seems very confuising for me
Mirco
I don't know how to explain you better
Read again the tree and apple example
Anders (izzno / gooood) 🇳🇴
separate the variables. clean your code.
inchidi
it seems very confuising for me
def update_or_create(defaults, **kwargs):
if self.model.objects.filter(**kwargs).exists():
obj= self.model.objects.get(**kwargs)
obj.update(**defaults)
return obj, False
else:
obj= self.model.objects.create(**kwargs)
return obj, True
inchidi
not literally equals with this because actually django use atomic transaction. but basically this function produce similar behaviour
Mirco
inchidi
sometimes familiar codes easier to read than human languages tho 😂
Mirco
🤣 also docs mentions the piece of code Django runs under the hood
dhelbegor
Hi guys, can someone tell me how I can register my models on LogEntry without using admin.py?
Dev
Kiran
Hi, how can I upload media files on my django app to dropbox. I'm using heroku for hosting but the media files get deleted after a day
Sander
Kiran
Anders (izzno / gooood) 🇳🇴
Have any of you used Mongo in pararell with sql to store files? If so, which ORM/modules did you use ?
Ильяс
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in /tmp/tmp1c_dj5pvbuild/mysql-python who can help? Cant install mysql-client
Nitesh
Is it necessary to use a web server for serving media files in production mode or we can continue using a media folder??
Mirco
Anders (izzno / gooood) 🇳🇴
Anders (izzno / gooood) 🇳🇴
It's not very complicated.
Mirco
Anders (izzno / gooood) 🇳🇴
Oh, yes better :)
Anders (izzno / gooood) 🇳🇴
but then it's abit more work and "complexety"
Anders (izzno / gooood) 🇳🇴
Or you could store them in Mongo. But it does not seem like someone here has done it yet, so ill post it when I'm done 😂
Nitesh
I'm using digitalocean.
Anders (izzno / gooood) 🇳🇴
Mirco
with django-storages is simple
Anders (izzno / gooood) 🇳🇴
of course, django has abstaction for everything :)
Mirco
Anders (izzno / gooood) 🇳🇴
in deed.
Yep
https://pastebin.com/WGrqrXuG
Yep
How to become both values and store it to the db? With the loop i just get 4 times the same data...
I get data with bs4 from 2 urls
Yep
But just the first url data get stored
Yep
The loop in the func.py works...with pycharm i get displayed the data from both urls
Anders (izzno / gooood) 🇳🇴
nope, there is not enough information to help you.
Yep
Im the func.py i return values from 2 urls
Yep
In models.py i save it... And witj the code just the data from the first url gets stored
Yep
Nametest is the function from func.py
Yep
There is no more 🤭
Anders (izzno / gooood) 🇳🇴
Is this your actual code ?
Anders (izzno / gooood) 🇳🇴
Your save is not inside your loop...
Yep
It is..i just edited it wrong
Yep
Its the main code for the 2 parts..return works
Yep
I get the data displayed right(Tested it with pycharm)
Anders (izzno / gooood) 🇳🇴
So your code is indented under your for loop ?