I found a solution to differentiate. Check is the object is iterable. If True then it is a list if not it is a single object. >>> hasattr(myDjangoSearchQuery, '__iter__')
FunkyBob: Thanks for the hint.
jcda has quit
moritz_s
lindylex: don't do that...
lindylex
Why?
moritz_s
A model instance can define __iter__, too
shibly has quit
lindylex
rats
jcda joined the channel
tezro has quit
moritz_s
Also in python generally you don't use hasattr for those kind of things, I'd say it's more pythonic to do try: iter(foo) exept TypeError: # not iterable
ArcaneWater has quit
v0r0nwe has quit
That doesn't prevent your function to fail if the model defines __iter__, however. Just do what FunkyBob said and always use a QuerySet
zanderle
I still don't understand why you need to differentiate? lindylex
FunkyBob
lindylex: you're doing it wrong
lindylex: why would you ever not know if you'r passing a list or an instance?
Quitta joined the channel
in fact, why would you write a function that accepts both?
matcom has quit
basically, the solution is... don't ever put yourself in this position
lindylex
FunkyBob: I need to be able to handle both that is why.
kuter joined the channel
moritz_s
lindylex: you should probably paste (on dpaste.de) your function and the places where you call it
Then we can tell you how to change it so that you don't need to make that distinction
FunkyBob
lindylex: why??
again, tell us more
why woul you call geT() sometimes and not othertimes, for what to pass to this function?
what is thisfunction?
zanderle
lindylex, there is most certainly a better solution
lindylex
Those are spec that were sent to me.
MrGix joined the channel
sbasso joined the channel
matcom joined the channel
FunkyBob
...
so when we kept asking for more information... you had it, but just refused to share it?
graffix222 has quit
staranjeet joined the channel
lindylex
No that is not what i was doing. I feel disappointed you would experience that.
FunkyBob
does the spec explicitly say you have to write a function that either expects a QuerySet or a Model instance?
lindylex: I'm not sure how much clearer you want us to make this
explain more about what you're doing
share with us details of your functions
and the actual constraints you have
jonalv joined the channel
wili joined the channel
Quitta has quit
staranjeet
Hi all
zanderle
Hi
FunkyBob
but as I said before.... writing a function that either takes an instance or a queryset in the same argument... is BAD DESIGN
My function accepts a QuerySet. And I dump that as a JSON object to a file.
FunkyBob
staranjeet: where?
jonalv is trying to run the 1.9 intro manual but has problems one the first freaking page :( and is just concing himself to actually retrace his steps one time beofre formulating a qeustion :)
lindylex: so ... what's the 1 stuff all about, then?
moldy
lindylex: querysets are always iterable, so no need to check for that :)
staranjeet: don't forget to make the PR against master and not the 1.8 branch
moldy
FunkyBob: ;)
lindylex
i appreciate all the help. I probably need to think about it some more. Thanks again for the assistance. It was truly appreciated.
jcda has quit
brat197 has quit
brat197 joined the channel
staranjeet
sure moritz_s
jcda joined the channel
moldy
lindylex: from what you told us so far, all you need to do is replace .get() with .filter() where you get the object
lindylex: alternatively, if you do not want to change the .get() call, you can do this: my_function([myobject])
synapps has quit
lindylex
moldy:Yep I noticed that also.
v0r0nwe joined the channel
I see that converts it to a list
zanderle
lindylex, and don't hesitate to ask if you need more help
people here are very willing to help
you just need to be willing to provide the necessary information in return
FunkyBob
lindylex: but please... explain the _whole_ problem
zanderle
(which you would think goes without saying... but doesn't)
sbasso has quit
lindylex
I noticed and this is the best resource. I truly appreciate your offering everyone. Especially you Funkybob. Time and time again you have been extremely responsive.
moldy: your suggestion solved my problem. "alternatively, if you do not want to change the .get() call, you can do this: my_function([myobject])"
carpediembaby
Hi, I want to include a library into my app and use it within the application. I created a lib folder in my project directory and tried to import from it but it doesn't get recognized. Could someone tell me how to do this?
moldy
lindylex: :)
linovia joined the channel
carpediembaby: which library? is it packaged properly? available on pypi?
Itkovian has quit
moritz_s
wili: it seems that the app that contains the Relationship model is not in INSTALLED_APPS
carpediembaby
moldy: it is my own. So i just want to include my own functions and use them within the django project. But they don't fit into the models/views category so i want to keep them separate
Itkovian joined the channel
moldy
carpediembaby: python2 or python3? do you have an __init__.py file in the lib directory?
wili
moritz_s but how it is possible that it works well in 1.9.1
moritz_s ah there is the thing.. its looking for django_dag.Semantic but Semantic is not in the app but in my project Semantic.Semantic
carpediembaby
moldy: its 2.7.6 , ah yes, I was missing the init.py in the lib directory i created. Stupid mistake .. Thanks!
staranjeet
should i update the PR or create another
wili
moritz_s full error semantic.Semantic.children: (fields.E331) Field specifies a many-to-many relation through model 'django_dag.SemanticEdge', which has not been installed.
FunkyBob
staranjeet: update
kunalg joined the channel
realnot
guys I don't figure out how set my settings. I created a dir "settings" inside the project dir, the i created my own settings like "base.py", "local.py", "deploy.py", the I exported DJANGO_SETTINGS_MODULE='project.settings.local'. The server run properly, the shell too, but when i tri ti print for example "BASE_DIR" the interpreter say it doesn't exists
wili
moritz_s so its problem that I will put the name of the model but not the location of it
realnot
*then
FunkyBob
realnot: print how? exactly what did you run?
wili
moritz_s fixed by class Semantic(node_factory('semantic.SemanticEdge')): vs class Semantic(node_factory('SemanticEdge')):
thanks
FunkyBob
realnot: also, you might want to look at django-classy-settings ... helps avoid the pains of multi settings files