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
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
inchidi
Yup thats what i am gonna do. Thanks for the discussion
sure you're welcome, one thing that am not sure is whether you should override Meta.validators or validator args for those fields tho
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?
Anders (izzno / gooood) 🇳🇴
How do I delete the Instance with a MenyToMany field when there are no more models connected to it?
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.
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
Mirco
No, when / if it has no owner
Did you specify on_delete rule ?
Guillermo
Did you specify on_delete rule ?
Its a manytomany relationship
Mirco
Its a manytomany relationship
Yup, forgot it 😓 it's the weekend 🤣
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
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?
Denys
Hi everyone)
Loki
how's your views?
Sorry, but what do you mean? :D
inchidi
Sorry, but what do you mean? :D
did you write your view function based or class based? try share your code of your view
inchidi
Oh, sure https://dpaste.de/ztuq
try this request.data['point_id']
inchidi
eh sorry, you already validate() it, then you can use serializer.validated_data['point_id']
Loki
thank you
inchidi
well that's not working
what you get from that btw?
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
.
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
request.body is dict like object, so you can make this: import json json_body = json.dumps(request.body)
.
from serializer which validates your request
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
serializer.is_valid() not serializer.is_valid
.
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
#ask how to import export with ajax in django ?
familiar with drf? if not, try learn about it first. https://www.django-rest-framework.org/ trust me its not raw solution for you but worth in the end
tk
Can anyone provide CV sample of Django
tk
Guys please give sample cv
R
Guys please give sample cv
https://duckduckgo.com/?q=sample+cv+django
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"}
inchidi
you're welcome 👍
Aadhi
Can we implement payment gateway using Django
𝐁𝐋𝐀𝐂𝐊𝐒𝐓𝐀𝐑
Yes
Rammanoj
Can we implement payment gateway using Django
yep, there are packages to that, you can find some here https://djangopackages.org/grids/g/payment-processing/
Aadhi
Thank you so much guys
Nichita
Hi, can I use authenticate method from django.contrib.auth with email but not with username? How?