| airstrike | you import the class, create an instance and then magic happens |
| ameoba | So, I'm looking at http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser and wondering how, under the hood, threads are handled. Are they recycled or does each request get a new thread? |
| JohnnyL | I get: >>> r = test_api.TestAPIUsage >>> r.test_aim_calls <unbound method TestAPIUsage.test_aim_calls> >>> r.test_aim_calls() Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: unbound method test_aim_calls() must be called with TestAPIUsage instance as first argument) |
| synic | JohnnyL: you either have to create an instance of TestAPIUsage or declare the method as static |
| JohnnyL | r is the instance |
| synic | r isn't an instance |
| synic | r is trying to capture the return value of the function |
| reesefrancis | how can I unregister models from the admin site? I've created an admin.py and I have to unregister them |
| igors | reesefrancis: admin.site.unregister(MyModel) |
| jim--- | Couldn't you just remove them admin.py? |
| Powerplay | andym, hmm tried the initial in the form without succes http://dpaste.com/150905/ |
| andym | Powerplay: you read the docs on this? |
| Powerplay | andym, http://docs.djangoproject.com/en/1.0/ref/forms/fields/#initial |
| Powerplay | that[ what i read |
| andym | which is completely different from your code :) |
| andym | forms.ForeignKey? |
| Powerplay | andym, i think it's the ForeignKey field that gives the probnklem |
| Powerplay | exactly |
| whatupderek | is there a way to have an inline for a UserProfile? |
| Powerplay | but this is the model blog = models.ForeignKey(blog) |
| whatupderek | where UserProfile is an inline for User |
| Powerplay | andym, what do you reckon for the primary key? |
| sachman64 | I thought I remember reading somewhere that you have to have both the project path and the project's parent path on sys.path to make things work. Is that true? I think I'm getting some weird behavior because of that |
| subsume | depends on how you set things up |
| subsume | whatupderek: an inline...... sure. |
| subsume | Powerplay: what do you mean 'reckon'? |
| whatupderek | it's saying something about nothing having a foreign key to the user model |
| subsume | whatupderek: well... does your userprofile have an FK to the user model? |
| whatupderek | because the 3rd model is related to UserProfile |
| whatupderek | yeah |
| subsume | third model? |
| whatupderek | yeah |
| subsume | third model? |
| JohnnyL | synic thanks, I tried the following implementation but still have not had success... http://code.activestate.com/recipes/52304/ <--- is this even valid?? |
| Powerplay | subsume, reckon as in think |
| subsume | Powerplay: think what? |
| Jonty | Django svn is complaining about a CSRF token not being there, but I've not turned on protection using middleware or decorators. What's going on? |
| apollo13 | JohnnyL: why not use @classmethod? |
| Powerplay | subsume, think about this 'hi what is the best way to pass a value from a view to a form? http://dpaste.com/150887/ ' |
| subsume | what's the best way to apss a value from a view to a form? |
| JohnnyL | apollo13 not familiar with @classmethod, but I'll look into it. (can you guys recommend a good book on python?) |
| apollo13 | python in a nutshell by alex martelli |
| apollo13 | at least if you know another programming language |
| Powerplay | subsume, yup, or alternatively predefine a value in a form |
| apollo13 | it surely isn't a tutorial style book, more like a reference (but again not really a reference, somewhere between ;)) |
| subsume | Powerplay: why? |
| Powerplay | subsume, to avoid bothering users with difficult questions |
| JohnnyL | apollo13 looks good. |
| subsume | Powerplay: ... can you explain what you're trying to do ? |
| Powerplay | subsume, so I'd like to create different html links and render the same form with predefined values |
|
|
| subsume | your code snippets and your description make no sense. |
| subsume | create different html links and render the form with predefined values makes no sense |
| Powerplay | ok |
| subsume | you make no sense. try again. |
| Action: JohnnyL high fives apollo. thanks! |
| JohnnyL | works |
| Powerplay | subsume, well this is the model http://dpaste.com/150915/ and the forms works perfectly well. Though there is a dropdown for the posts to attach them to a blog |
| subsume | ok |
| subsume | so exclude the fields you don't want |
| Powerplay | subsume, so i exclude 'blog' but it[ a required field :) |
| subsume | ok, so pass in its value to the form and override form __init__ and set it manually in a save override |
| Powerplay | subsume, ok that makes sense |
| subsume | when you make sense, I make sense. |
| mad_moses | hi, i wrote a templatetag which returns a number, i can use it in my templateengine with {% mytemplatetag %}, but i want it in a if construction like {% if "3" > {% mytag %} %} but this throw an error, what can i do? |
| subsume | not that. |
| subsume | you can update the template's context |
| mad_moses | <- ? |
| subsume | basically you set the context dictionary key to be whatever value |
| subsume | and you can use it later in the template |
| subsume | but what is this mytag tihng returning? |
| subsume | as in, why does the templatetag have this value, but the view doesn't? |
| subsume | why not just pass it in from view |
| mad_moses | subsume, becauce i use it on all pages and i wont edit all my views |
| subsume | maybe use a middleware then? |
| subsume | what's the difference between editing all your views and editing all your templates? |
| mad_moses | subsume, i never write a middleware |
| subsume | ok |
| subsume | welp, you do now. |
| mad_moses | subsume, i can put mytemplatetag into my base.html and it will print on all pages |
| subsume | what is this thing you want to print? |
| mad_moses | subsume, an attribute of a model |
| subsume | model.get_attribute doesn't work? |
| subsume | {{ model.some_method }} |
| subsume | {% if "3" > model.some_method %} .... |
| mad_moses | subsume, good idea, i will try, thank you |
| eric6rm | Hi I have a question about deployment with nginx/apache using SSL |
| eric6rm | I have nginx recognizing the SSL certificate and passing onto apache |
| eric6rm | and on Apache, I'm using mod_python to serve Django |
| eric6rm | I think I'm supposed to somehow pass information from nginx to django so it will pass a secure response |
| eric6rm | but I'm not sure how to do this |
| subsume | django doesn't know or care if its SSL |
| eric6rm | subsume: I was under the impression that if it received a secure request, it would create a secure response |
| subsume | your webserver is in charge of that |
| eric6rm | subsume: what I'm assuming is that, in the Apache virtual host settings, I need to check if the request from nginx is secure, and then pass some info to Django |
| subsume | Oh I heard you. |
| subsume | the answer is no |
| subsume | even the virtual host doesn't care if its 'secure'. it just listens on 443 |
| Liberum | Is there a way to modify the queryset used in a ForeignKey field in the admin depending on the request? |
| eric6rm | subsume: maybe that's the problem? I have nginx listening on 443 and passing the request to Apache listening on 8000 |
| subsume | eric6rm: why this complex setup anyhow? |
| armorsmith42 | if I have a model with two foriegnkeys and I instantiate it with two instances of that model, is is supposed to automatically grab the keys of both, or just the first one.? I seem to be observing the latter. |
| kennethlove | i keep getting an error about django being unable to load a custom auth backend, but i've disabled that backend, restarted the server several times, and cleared all .pyc files. any help? |
| subsume | armorsmith42: ...huh? |
| eric6rm | subsume: I am trying to make a Django site work with an SSL certificate, and the Django site uses nginx to serve files. Is that particularly complex? |
| subsume | eric6rm: i don't understand the relationship between nginx and apache. and i don't understand why you're using mod_python |
| eric6rm | subsume: here's the whole story: I needed to move a Django site onto a Windows IIS server (yeah.. I know :( ). The only way to get Django to work on Windows, afaik, is to use mod_python. I use Apache to serve Django and nginx as a reverse proxy, serving static files and redirecting Django-related requests to Apache. |
| joerg | hi |
| subsume | i see |
| armorsmith42 | I've instantiated this model user_ing = UserHasIngredient(user=profile,ingredient=result) and, going through the server transation code in pdb I print user_ing.__dict__, which is {'user_id': 5, '_user_cache': <UserProfile: >, 'amount': None, 'ingredient_id': None, '_ingredient_cache': <Ingredient: vodka>, 'time': datetime.datetime(2010, 1, 26, 17, 51, 31, 853970), 'units': None, 'id': None} |
| subsume | welp, that solves it then |
| joerg | is it easy to extend the admin interface? |
| armorsmith42 | hello joerg and welcome! |
| subsume | armorsmith42: maybe result is indeed None |
| joerg | I mean if I use different auth methods with django e.g. LDAP it would be nice if I could manage users there.....stuff like that |
| joerg | armorsmith42, thanks ;) |
| armorsmith42 | that would indicate that the vodka, which does exist in the database, does not have an id |
| subsume | armorsmith42: result == None |
| joerg | I mean.....should I code a django app that can manage ldap users from scratch or try to somehow extend contrib.admin? |
| armorsmith42 | no, result = <Ingredient: vodka> |
| armorsmith42 | this would be tragic otherwise |
| subsume | armorsmith42: does it have a pk? |
| armorsmith42 | ah. no it does not. this indicates that the rabbit hole goes deeper. thank you |
| Powerplay | is it possible to hide just one of the {{ foo_form|as_uni_form }} fields? |
| mattmcc | What do the uni-form docs say? |
| Powerplay | mattmcc, no clear answer here http://github.com/pydanny/django-uni-form/blob/master/docs/usage.txt |
| Liberum | Does the exact functionality of ModelAdmin.formfield_for_foreignkey not exist for many-to-many fields? |
| Powerplay | mattmcc, and this doesn't work http://dpaste.com/150930/ I know about the exclude in form option but I; m trying to avoid that and find a method in the template |
| rozwell | Liberum: if you found that one, i'm not sure how you missed formfield_for_manytomany |
| Liberum | rozwell: Heh, I guess ticket #11882 would explain - "Documentation missing for django.contrib.admin.ModelAdmin.formfield_for_manytomany" :) Thank you! |
| DjangoBot | http://code.djangoproject.com/ticket/11882 |
| subsume | I've got a unit test which isn't loading a particular fixture, silently. what's probably wrong? |
| flagg0204 | im trying to test wether a transaction is an "UPDATE" or an "INSERT" in my django app. I think I need to overwrite the save() method for my modelform. But how can you test if something is an update/insert before calling the super(ModelForm, self).save()? |
| subsume | flagg0204: background? |
| flagg0204 | subsume - ?? |
| subsume | or not. |
| flagg0204 | subsume - i dont understand the question |
| subsume | pretend you do. |
| flagg0204 | subsume - and this is helpful why? |
| subsume | what are you trying to do? |
| flagg0204 | i have a modelform and view to allow me to add and edit objects for that model. I have a save() method in the modelform. Im trying to figure out how to test whether a transaction is an update or an insert |
| synic | flagg0204: if self.id is None, it's an INSERT |
| flagg0204 | synic - the model does not have an id column. it has a foreinkey to another table |
| synic | oh wait, it's a ModelForm, nevermind. |
| flagg0204 | fk = domain |
| synic | all models have an id column |
| mattmcc | obj.pk points at your PK field, whatever its name is. |
| flagg0204 | mattmc - ah isee |
| flagg0204 | so could you do if self.obj.id is None? |
| flagg0204 | for a test |
| subsume | pk |
| subsume | not id |
| subsume | but yes. |
| flagg0204 | if self.obj.pk == None |
| flagg0204 | or if not self.obj.pk |
| flagg0204 | i guess either way works? |
| subsume | you could do |
| mattmcc | Er, 'obj' is meant to be replaced with 'whatever your model object is'. |
| subsume | if self.pk in [None] |
| mattmcc | ModelForms don't literally have an 'obj' attribute. |
| flagg0204 | mattmc - yeah i got that :) |
| flagg0204 | mattmc - just using it for an example. |
| flagg0204 | ill give that a shot. |
| flagg0204 | thanks |
| flagg0204 | interesting. well bow django is complainging that my modelForm does not have an attribute pk |
| sachman64 | for adding apps to INSTALLED_APPS, can I do just 'app' instead of 'project.app'? |
| sachman64 | if the project dir is on sys.path |
| deorbital | hi |
| deorbital | can someone please enlighten me how this should be used in a form? http://jannisleidel.com/2008/11/autocomplete-form-widget-foreignkey-model-fields/ |
| deorbital | for the life of me i can't figure it out |
| cmwslw | wouldn't it be taxing on the database to call something like Entry.objects.order_by('blog__name', 'headline') |
| cmwslw | i'm guessing that in order to sort, the blog for every entry would have to be retrieved to get the name. |
| cmwslw | or are databases fast at doing these sorts of things |
| oliland | how do you guys handle mobiles? |
| oliland | do you override your templates directory when someone arrives at your mobile site? |
| mattmcc | cmwslw: Depends on the table(s) and indexes. |
| cmwslw | mattmcc: what if it was just a foreignkey to a model with an IntegerField? I'm deciding if I need to maintain copies of the integer in the model I want to sort to speed it up |
| cmwslw | keeping a copy is error prone and messy, but if my order_by is really slow it might have to be that way |
| mattmcc | cmwslw: Well, do an explain plan, see if it is slow. |
| mattmcc | And maybe indexing differently will help. |
| __machine | what is currently the best way to replace or extend the User model? i don't just need to add different fields... i need to replace existing fields... username needs a longer max_length and to accept email addresses... and the other CharField should use a subclass of CharField that i have which when represented in a ModelForm will strip leading and trailing white space from the values before validation... ? |
| dfjoerg | AUTH_PROFILE_MODULE |
| mattmcc | A custom auth backend will allow you to authenticate users by email instead of username. |
| lawgon | or by fingerprints |
| oliland | or with social authentication |
| __machine | mattmcc: so create my own User class with username, email, firstname, lastname and all other fields i need (using my subclassed CharField) and an fk back to django User model... and use custom auth backend to authenticate and return that user instead? |
| anteatersa | doesn anyone know how to access request.user in models.py? |
| mattmcc | anteatersa: Generally, you don't. Models shouldn't depend on the existence of an HTTP request to function. |
| mattmcc | That's what views are for. |
| anteatersa | hmm, good point |
| anteatersa | will put in admin.py, thanks |
| mattmcc | http://www.b-list.org/weblog/2008/dec/24/admin/ |
| kennethlove | is it possible to chain model managers? like i have active() that gets items marked as active and published before now. i'd like to have featured() that gets active items that are also featured w/o having to replicate the code of active(). is this possible? |
| anteatersa | perfect cheers mattmcc |
| mattmcc | kennethlove: Well, do the functions return querysets? |
| kennethlove | mattmcc: yes |
| mattmcc | So, there you go. |
| symbiotic | sick post |
| kennethlove | i'm sorry but i need a bit more than that. I've tried doing: return super(Model, self).get_query_set().active().filter(blah blah) but i get errors on get_query_set not having a method active(). |
| mattmcc | Well, if your manager has methods active and published, and you want published to include the active filter, it'd just be 'def published(self): return self.active().filter(...)' |
| kennethlove | hm, thought i had tried that but i'll give it another shot. thanks |
Popular searches: