I’ve got a model whose `save()` method doesn’t write to the database, but makes a rest API call
but, through that save, I would love to add ValidationErrors if the API call fails, and tie those to the specific fields that failed
Looking at the source, I don’t think (for example) the admin lets me do this (since, is_valid() is separate from save(); and through the API, I Don’t have any analog for is_valid())
kbck has quit
but is there any analog for clean error handling via modelforms or some such?
I guess I should try this out before asking too many questions but I like picking other smart people’s brains before heading into those weeds :D this is a fairly unique use-case but I figure Django probably has some nice in-roads for making this happen
hpanago has quit
dang`r`us
if it's a django ORM model I'd avoid contorting save() like that
but hm, who knows.
HowardwLo has quit
black has quit
henrydangprg has quit
holms
jessamynsmith: my issue is most weirdest i had ever in my life. i've rolledback repository to like 20 commits, and this exception is still there. i mean at least tests did work back then. i've even create droplet on digital ocean.. and every singe commit gives me this exception.. all versions of python packages are freezed .. this is only due to depedency.. ijust can't see any other reason
roomcayz has quit
jessamynsmith
ugh
holms: it's closed-source?
mrb101 has quit
holms
jessamynsmith: yeah, but doesn't at this time, i can give you a shell lol
nazarewk has quit
jessamynsmith
*thinking*
what I really want to do is debug it
holms
i'd be deadly grateful to you.. because my head is blowing up. and yeah we have some packages directly from git without versions.. that might be a case
tmux session is waiting for you all i need is a ssh key
jessamynsmith
holms: -> dm
hck89 has quit
jas02_ joined the channel
themediator
Hey guys, I'm using the User class from django.contrib.auth.models as a foreign key in one of my models. What is the best way to pass the username of that key to the DRF serializers to get it to show me the username? Currently I get the PK ID #
fr33co joined the channel
fr33co has quit
hck89 joined the channel
cnk
do you want only username? or username and id?
tpete joined the channel
themediator
Only username
I figured I could just put def __unicode__(self): in the User model, but I don't want to edit that model if I can help it
cnk
There isn't a way to get username without doing a query into user
jas02_ has quit
DRF can give you user id from your related model - that's what is in the db
themediator
Does the default auth model require username to be unique? If so I could just store the username instead.
cnk
but to get to username, it has to actually query user
bwreilly has quit
I would just add select_related('user') to your related querysets and then have a serializer model field that is obj.user.username
hello guys, Im trying out django-oscar on windows and I am having an error when I run the make sandbox. https://dpaste.de/R56w can anyone help ? Thanks
cnk
so at line 3: author = SerializerMethodField()
then make a method called get_author that returns author.username
but be warned, that will do n+1 queries for your recipe list endpoint
so you will need to make sure that your recipes queryset has select_related('author') so the author objects are selected along with the recipies
1) does it work and 2) you still need select_related and 3) definiing a class is just as much code as creating the method
but whatever, you still need select_related
themediator
Serializers.RelatedField does that automatically I think
hck89 has quit
at least, it's working for me
LysergicDreams has quit
cnk
are you logging your queries
LysergicDreams joined the channel
you are getting the data - but I bet doing 2 queries to get it - one to recipies and one to users
ironfroggy has quit
ironfroggy joined the channel
OK outta here
cnk has quit
ironfroggy_ joined the channel
nzey joined the channel
aristippos has quit
wub_wub has quit
LysergicDreams has quit
nzey has quit
LysergicDreams joined the channel
ironfroggy has quit
woltman joined the channel
Debnet has quit
HowardwLo has quit
HowardwLo joined the channel
HowardwLo has quit
Debnet joined the channel
HowardwLo joined the channel
HowardwLo has quit
detseg has quit
ironfroggy_ has quit
ironfroggy joined the channel
ironfroggy has quit
ironfroggy joined the channel
the_rat has quit
Ryanar has quit
Leeds joined the channel
Ryanar joined the channel
olrrai joined the channel
iiie has quit
re1_ joined the channel
ironfroggy has quit
detseg joined the channel
ironfroggy joined the channel
zoolook has quit
BananaDisco has quit
lolidunno has quit
darylantony joined the channel
ironfroggy has quit
darylantony
I think I'm misunderstanding the `choices` attr in CharField. I'd like my template to output the 'label' text as in described here: http://dpaste.com/0AE9KGF