djsnoops: Mmm, nope, either way you do it it does a separate join :(
.exclude(Q(foo__bars__thing='xyz') & ~Q(foo__bars__eggs='abc')) or .filter(~Q(foo__bars__thing='xyz') & Q(foo__bars__eggs='abc'))
custom sql time i think
Knyght
django made me forget everything I ever knew about sql. I'm still not sure if this is a good or bad thing.
alexhayes
its a good thing
no, its a bad thing
:P
yask has quit
maugzoide joined the channel
jay-tyler has quit
ArtisOracle joined the channel
jay-tyler joined the channel
BabySuperman has quit
maugzoide
I have reading a lot about CQRS, DDD and other useful patterns. I was thinking how it is related to Django.
For example, I am facing a problem where I have some calls to an external service in my views.
I think it is reasonable to use Django signals but in the end I don't know if I am solving the problem or just moving it elsewhere. :)
What is your opinion?
rain0r has quit
a_little_birdie joined the channel
tbaxter
I don’t use signals unless I have no better plan.
if I’m already in a view, I’ve got multiple better plans.
geek joined the channel
bcSquared has quit
thinkt4nk has quit
djosh has quit
a_little_birdie
Silly question: I have an unsaved model instance.. I've already done id=somenumber to manually set the id.. but later on in the code want to change my mind and allow it to be assigned from the sequence upon insert.
tbaxter
alexhayes: did you try this order: filter(foo__bars_eggs=“abc”).exclude(foo__bars__thing=‘xyz')
kutenai
I am trying to speed up my unit tests in 1.8. I am doing DB access, so it is building the test DB. This takes about 15 seconds to "Render Model States", then about 20 more seconds to apply migrations.. ouch
a_little_birdie
Assigning id=None doesn't work..
tbaxter
I think you want to filter down first, then throw some out. But I could be wrong.
oh jeebus, not again
kutenai
I have tried --keepdb, but that does not seem to help. I am using sqlite as the test DB..
Muchoz joined the channel
tbaxter
a_little_birdie: why are you manually setting the PK?
Hairy joined the channel
paste your model
kanja joined the channel
a_little_birdie
tbaxter .. I have a tree structure represented in the database. Sometimes I have to save a node in the tree and find that the parents of that node do not exist yet.
tbaxter
no no god no
Paste your model
a_little_birdie
All ancestor nodes must be saved first/.
codey_ has quit
So, when I am iterating through stuff I don't necessarily know whether a node needs to be inserted until I've processed the whole tree. So I create a node instance to preserve the relationships.
Thanks I already looked at it.. we are writing our own because we have some more complex needs, eg versioning, derived values, complex data types...
tbaxter
paste your model
slamice has quit
transit has quit
Earlo has quit
actually, paste the view, too.
maugzoide
tbaxter: what is your other plan
tbaxter
I’d just do it in the view, most likely.
dcrouch joined the channel
I mean,, why fire off a signal for something I can just do now. it’ll be much clearer.
maugzoide
tbaxter: what if someones changes a field that should be updated in the thirdy party service?
tbaxter: the /admin for example.
eka joined the channel
tbaxter
Different problem. In that case, I’d probably write a custom save()
delizin
By design the django.contrib.auth @login_required decorator doesn't check to see if a user is_active, instead this is left to the login function to prevent an inactive user from logging in. My concern with this approach is that if a user account is deactivated, but the user has not yet been logged out then they can continue viewing pages and there is a potential of them maliciously altering data.
alexhayes
tbaxter: Unfortunately that still produces the same outcome, joins for the filter and subselect for the exclude
a_little_birdie
So, nobody can tell me how to tell django orm that the integer id I assigned earlier (but didn't save) isn't the one I want, that I wish to take back that assignment and make it unassigned again?
amites has quit
maugzoide
tbaxter: I am confused. The save() of a model should be only to deal with the storage, people say...
delizin
Is that a non issue? And if it is a issue what would you think the best way to solve it would be? Possibly editting the @login_required to check if the user is active or creating a middleware to check log out users that are inactive?
tbaxter
a_little_birdie: I’m fairly sure I can tell you. However, I’m still waiting for you to paste the model (and view)
maugzoide: who are these people?
maugzoide
tbaxter: lots of blogposts I am reading these days.
tbaxter
Seriously, though. If it’s something I need to check/do before I can safely save, I would have no problem with a custom save()
but then, I’m not a fan of signals.
eka has quit
ArtisOracle has quit
I think they’re difficult to debug and make things more opaque than they need to be
maugzoide
tbaxter: even Martin Fowler when he talks about CQRS.
a_little_birdie
Ahh I didn't know you were asking me to paste the model.. thought that was someone else
krawchyk has quit
This code is actually in a form save method.
maugzoide
tbaxter: You write commands and events in different files (Python) and call them when needed.
a_little_birdie
The model is dynamically generated so that's a bit complex too...
tbaxter
a_little_birdie: then paste the model, the view and the form
KlausedSource_ has quit
then just start with the model.
I’m not going to guess what fresh hell you have wrought
edgabaldi has quit
maugzoide: well, I don’t know what to tell you. I don’t know who Martin Fowler is, I’ve never heard of CQRS before today. I can only tell you what I’d do, writing real-world code for real-world developers to maintain.
a_little_birdie
Ok gimme a few minutes, thanks
ubuntu_aze joined the channel
domino14 joined the channel
tbaxter
If you feel more comfortable with a signal, knock yourself out. They do work.
ArtisOracle joined the channel
Kayra has quit
teebes has quit
knbk has quit
domino14 has quit
lmn_ has quit
eka joined the channel
djsnoops has quit
skift joined the channel
dronezero has quit
transit joined the channel
discypher joined the channel
the_rat has quit
tbaxter has quit
bkeating has quit
stymo has quit
rpkilby has quit
ePirat has quit
flobin has quit
transit has quit
ePirat joined the channel
ArtisOracle has quit
lacrymology has quit
solidether has quit
discypher has quit
pembo13 has quit
stantonk_ joined the channel
discypher joined the channel
Guest61118 has quit
stantonk has quit
Melamo has quit
teebes joined the channel
transit joined the channel
kalem has quit
stantonk_ has quit
stantonk joined the channel
manbehindthemadn has quit
msc has quit
doubleo2 joined the channel
realnot has quit
msc joined the channel
delizin
I ended up implementing some very simple middleware that checks if a user is_active and logs them out if not. Not sure why they decided not to include this in the django.contrib.auth package by default, but seems like a pretty big security hole.