inchidi
Yes
maybe explain what you really want to do? i smell xy problem here
Anonymous
So basically this is whats happening, i have two unique fields in my model, what happens is serializer makes 2 queries for validating them.
What i was thinking of doing was to override serializers field validation and in def validate make a single query using Q to validate uniqueness of both fields
inchidi
Anonymous
Yes it does i just want to reduce db queries
inchidi
then for this case instead validate_<field name>(), validate() should fit with what you need right? what do you think?
Anonymous
I was thinking the same
inchidi
yeah me too, then i think you can just validate there and remove default validation for those fields
Anonymous
Yup thats what i am gonna do.
Thanks for the discussion
Anonymous
Ohh ok,
I will look into both ways abd let you know what i used.
inchidi
sure 👍
Loki
How can I convert request body to json and assign it to variable?
007
Anders (izzno / gooood) 🇳🇴
How do I delete the Instance with a MenyToMany field when there are no more models connected to it?
R
Anders (izzno / gooood) 🇳🇴
Null=true?
hm, its the other way around. I am sharing carts between users and if everyone renouces the cart then its left orphaned.
Mirco
Anders (izzno / gooood) 🇳🇴
No, when / if it has no owner
R
By signals maybe?
Anders (izzno / gooood) 🇳🇴
By signals maybe?
Yes thats possible, but I was hoping it was something I missed :D
Guillermo
@izznogooood there is a signal, m2m_changed, iirc
Anders (izzno / gooood) 🇳🇴
Signals it is then....
.
I hate signals
Guillermo
Anonymous
I was reading a django article and found this:
Mistake No. 4: Writing Fat Views and Skinny Models
Writing your application logic in views instead of models means you’ve written code that belongs in your model into the view, making it “fat” and your model “skinny.”
You should write fat models, skinny views.
Break logic into small methods on your models. This allows you use it multiple times from multiple sources (admin interface UI, front-end UI, API endpoints, multiple views) in a few lines of code instead of copy-pasting tons of code. So next time you’re sending a user an email, extend the model with an email function instead of writing this logic in your controller.
can anyone explain me what he means by adding email logic to Models?
models are just database tables, how can it have send email logic or function?
.
inchidi
inchidi
like what erich said, you can also read about custom model managers, so you can do something like this Email.custom_objects.is_email_stored('sample@mail.com')
Anonymous
ahhh it's awesome...
thanks ...
Anonymous
It really is a great TIP
Loki
If POST request looks like this https://dpaste.de/eeM0, how can I get point_id's value (line 21) and assign it to variable?
inchidi
Denys
Hi everyone)
Loki
inchidi
eh sorry, you already validate() it, then you can use serializer.validated_data['point_id']
Loki
Loki
Loki
thank you
Loki
keyerror
inchidi
keyerror
eh i think its because you use CheckSerializer instead PrinterSerializer for (de)serializing your data here https://dpaste.de/ztuq#L3
inchidi
if you share your serializers also, it will help for sure
Loki
Here they are
https://dpaste.de/Me1a
Loki
Do you know, the way to convert request body to JSON. I need it here https://dpaste.de/ztuq#L49 but didn't find solution yet
.
.
.
from serializer which validates your request
Loki
.
Loki
got "Error binding parameter 2 - probably unsupported type." from both ways (json and serializer)
.
send me code
Loki
https://dpaste.de/ozsa
Anders (izzno / gooood) 🇳🇴
Anders (izzno / gooood) 🇳🇴
I added an owner to separate the shared from the owner, the owner is a fk so the whole problem went away
.
https://dpaste.de/ozsa
if you want to return reques body as json add this to the bottom after calling is_valid():
return Response(serializer.data)
Anders (izzno / gooood) 🇳🇴
Do you guys ever use context for user related content? As long its connected to a user you can pretty much user.related_name.all your way to anything.
Bug
Gud day Hus
Pls where can I get a good django cms tutorial
Loki
Ok, I am probably the dumbest person in the wolrd. Couldn't use JSONField because forgot to connect postgres base and was using default sqlite
Roni
#ask
how to import export with ajax in django ?
inchidi
tk
Can anyone provide CV sample of Django
tk
Guys please give sample cv
inchidi
@lokithecreator "serialization (or serialisation) is the process of translating data structures or object state into a format that can be stored" https://en.wikipedia.org/wiki/Serialization
your data format and serializer fields doesnt match, what do you expect? you should send json that fit with your serializer, sample:
{"name":"SampleName", "api_key":"SampleKey", "check_type":"SampleCheckType", "point_id":1"}
Loki
inchidi
you're welcome 👍
Aadhi
Can we implement payment gateway using Django
𝐁𝐋𝐀𝐂𝐊𝐒𝐓𝐀𝐑
Yes
Aadhi
Thank you so much guys
.
Nichita
Hi, can I use authenticate method from django.contrib.auth with email but not with username? How?
Mirco