|
I know this is a big vague, but hopefully someone may have an ideacode:
http://dpaste.com/45018/ - Full error message http://dpaste.com/45019/ - My views, line 100 is the delete part
|
# ¿ Apr 15, 2008 21:58 |
|
|
# ¿ Apr 30, 2024 04:47 |
|
Wulfeh posted:I know this is a big vague, but hopefully someone may have an idea Oh woops, contact_record = Contact was left there by accident when I was trying to debug. That can be ignored really. No Safe Word posted:Also, from your views: I remember passing over that when I started learning Python a few weeks ago, but yea, now it will stick with me since you mentioned it.
|
# ¿ Apr 15, 2008 22:15 |
|
Totally forgot about this, but since I did get this fixed I thought I should mention what was causing it. Wulfeh posted:I know this is a big vague, but hopefully someone may have an idea I had my objects set to a custom search manager in my models, and when I was trying to delete the model it was trying to use the search managers args, which I wasn't passing. Anyway long story short I now have: code:
|
# ¿ Apr 25, 2008 15:59 |
|
bitprophet posted:One way of accomplishing the task I wanted to show another way to accomplish this task, though I might be off a little on syntax. I thought modelchoicefields would be a better choice than radiobuttons, but that's just me of course, I am only 2 months old in django and web stuff in general, so take that as you will. Model I used the same one as Bitprophet Template code:
code:
Wulfeh fucked around with this message at 04:28 on May 13, 2008 |
# ¿ May 13, 2008 04:21 |
|
FrontLine posted:I want to use validation errors king_kilr posted:Use newforms Yea the old forms and manipulators are on the way out I believe. To do it in newforms, you would put something like this in your form class: code:
|
# ¿ May 14, 2008 21:02 |
|
Something I am having trouble with are perms, I want to do something like user.has_perm(perm_object), but IRC told me that has_perm won't validate a perm object. I am not sure how to go about checking some custom permissions, I am open to ideas. ( I am trying to restrict a fields choices with permissions ). Invalid code code:
ModelMultipleChoiceField(queryset=Tags.objects.filter(perms__exact=user__user_permissions)) Wulfeh fucked around with this message at 21:26 on May 14, 2008 |
# ¿ May 14, 2008 21:19 |
|
deimos posted:Gah, this is a pet peeve of mine, it's a bit wasteful and IMO makes it harder to read when you have a single method that does both: self.cleaned_data.get('bool_field', False) works fine to replace both of those. That's pretty cool, i'll try to start using that. Milde posted:.get('foo') Even better for the bool Honestly, it must be from the way I copied it from my editor, because my tab settings are set to 4 spaces. I don't see why indentation should even be mentioned, it's obvious I am totally trying to "break the standard" and be "unique". for the: if not ... in ... and the if ... not in ... is that just a preference of yours, or do most Python developers try to strive for the latter? (it's like asking "if there isn't this field in the cleaned data", or "if the field isn't in the cleaned data")
|
# ¿ May 15, 2008 05:27 |
|
It took me a few weeks of playing with the whole django framework and finally having that "Aha!" moment where you understand how all the different parts interact. I never knew about MVC frameworks, web development, databases, or anything of that sort before I started learning django and python, I had mostly only known how to do console stuff with C or C++. So it is kind of fun seeing how easy it is to create something and see results pretty much instantly. I also love how python is so easy to work with, compared to literally "fighting" with C++.
|
# ¿ May 17, 2008 02:54 |
|
Wulfeh posted:Something I am having trouble with are perms, I want to do something like user.has_perm(perm_object), but IRC told me that has_perm won't validate a perm object. I am not sure how to go about checking some custom permissions, I am open to ideas. ( I am trying to restrict a fields choices with permissions ). Answering my own question again, in case anyone finds it useful. This allowed me to add permissions from the admin panel to someone, and if they have those permissions, it restricts what options they can view in that choicefield. If they are a superuser, then they get all permissions. code:
code:
|
# ¿ May 20, 2008 03:54 |
|
Larry Horse posted:Anyone have any Django-based calendaring code they wouldn't mind sharing? It seems like a common use, but I don't see much sample code via Google. http://www.djangosnippets.org/tags/calendar/ There a couple there, and if those aren't exactly what your looking for, I am sure they would be good references
|
# ¿ May 21, 2008 18:10 |
|
politicorific posted:performing a len on database results - either djangobook or the documentation says not to do this: code:
politicorific posted:Third: Static pages code:
code:
politicorific posted:Finally I would like to make sure that my grammar is correct on this site I'm building. So I get something like "0 results" verses "1 result" - models.py has the meta tag. code:
So for what you wanted you could do code:
|
# ¿ May 22, 2008 20:09 |
|
http://www.djangoproject.com/documentation/db-api/#save-foo-file-filename-raw-contents Have you tried that out? save_FOO_file()
|
# ¿ Jun 3, 2008 08:39 |
|
Sock on a Fish posted:Say I want to weigh the items returned in a search based on what other users have selected for the same search. Should I create a new model and new record for every search? Should I add a dict to the model on the items being searched? Is there an easy way to serialize a dict and put it in the database? Can you explain this a little more? You mean like tags? Everytime a keyword is searched, add that keyword to the table if its not found, otherwise add the count for that keyword + 1. Something like that? ashgromnies posted:Yeah but it doesn't give me a model to store in the database if I use that. I could write raw SQL to do it but I want to do it "the Django way". The image isn't saved to the database it will be saved to your servers filesystem according to your upload_to and media_url Wulfeh fucked around with this message at 22:38 on Jun 3, 2008 |
# ¿ Jun 3, 2008 22:24 |
|
So is anyone going to Djangocon? I grabbed a pair of tickets this morning for my boss and I.
|
# ¿ Jul 31, 2008 18:18 |
|
Alright, got another problem that I am not quite sure how to approach. We are trying to split up a section of the site in to a multi-step process so it is easier for user's to complete the information, obviously this looks like a job for FormWizard. The problem I am having trouble with is that, not only do we take information for a model via form fields, but there is one part that requires the user to enter a search query and pick a person based on that query. What I don't know how to do is maintain the form-wizards state when the user goes for a search, and picks a user. If I leave the current url, they lose all the data entered, so you can't re-enter the wizard from where they left off. As an added bonus, they should be able to search and pick people several times. One idea I had was to add a form to the wizard where they entered their search queries and it would return back another form with a MultipleChoiceField with all the queries and they can choose who they wanted, but that could be a little difficult for the end user to see who they are choosing.
|
# ¿ Sep 25, 2008 19:40 |
|
bitprophet posted:AJAX Another clincher is that we try to stay as far away as possible from AJAX / JS calls to the DB. Reason is because we are diligent in being handicap friendly. This means screen readers have to be able to go through this and be A-Ok at reading what's going on. I think we may end up just using the form wizard for the model, saving it, then redirecting with the id in the url to the next step, and just have that step be repeatable. We had discussed this idea in length, but put it down at first because we felt it wouldn't be coherent enough programatically, but seems to be one of the few options.
|
# ¿ Sep 25, 2008 22:27 |
|
Fourthing the "hard to find poo poo you need in the new docs," and it isn't just because I memorized the the layout of the old one. It isn't clear where the links are going to lead sometimes and you have to dig from one page to the next to find what you need, unless you know the search term you want.
|
# ¿ Oct 8, 2008 22:26 |
|
nbv4 posted:get_profile returns an object, so to use it in a template, you must do something like "{{ request.user.get_profile.posts_per_page }}", which unfortunately doesn't work. That example you just put works perfectly fine, why do you say it doesn't? What bitprophet said is correct, if posts_per_page took some args, then you would have to do it the other way.
|
# ¿ Oct 15, 2008 21:59 |
|
Janin posted:
I was under the impression that class Meta ordering was "bad", something to do with inheritance, I forget. It was something mentioned by David Cramer at djangocon. Does anyone remember the exact reason why?
|
# ¿ Nov 6, 2008 22:03 |
|
I watched the Djangocon vid again, and he mentioned that when you start using joins across several tables with Meta Ordering, it will do ordering on every table where Meta ordering was specified. So for large datasets, it will be ordering itself several times over, which you probably don't want it doing.
Wulfeh fucked around with this message at 16:19 on Nov 7, 2008 |
# ¿ Nov 7, 2008 16:07 |
|
Ansible posted:I have a ModelForm based on the Consumption model, which works for users to add foods to their log. (I'm assigning User in views.py after they POST the form with User excluded, is there a better way to do this?) Doing it like that is fine, there are a variety of ways to accomplish this. Another option would be to do this is by passing the user into the form, and overriding save to add the user in. Like so, code:
Ansible posted:I run into a problem with the Nutrient table. I have a whole gaggle of Nutrients, but only want to show a handful. The only way that I've found I can access the table is with a loop through consumption_item.measure.food.nutrient_set.all - but I can't filter that to only include Nutr_Def_id = 1 (for example). I want to do something like {{ consumption_item.measure.food.nutrient_set.(filter(id_Nutr_Def=1)) }}. I wouldn't do this in the template, filter the nutrients you want from the view, and pass it from the view to the template.
|
# ¿ Mar 25, 2009 22:00 |
|
Mashi posted:Measures.objects.select_related('food') will produce a join on your food table which loads the related food instances in bulk, rather than running individual queries for them when they are accessed via the measure instances. This needs to be stressed, if you fail to implement this you are going to be making a ridiculous amount of unneeded queries to the database.
|
# ¿ Apr 16, 2009 02:22 |
|
king_kilr posted:No, what needs to be stressed is that that doesn't change the results returned, it is merely an optimization, start righting your site without any optimizations, and add as needed, if you just start sticking select_related throughout your code wiht no thought you are going to generate lots of massive joins that are far worse than extra queries. I agree, but it is an easy optimization to make if you know you going to be using those relations and you are loading several instances of that model.
|
# ¿ Apr 16, 2009 16:20 |
|
I had no problems developing on a windows machine with Django back in 0.96, and we used a Debian box for our production server. I used Notepad++ for editing and tortoise svn as an interface for using svn on windows. As for the python interpreter, I don't know if it runs any faster or slower, but I don't remember running into anything that stopped me from developing. Just make sure to setup all your path variables correctly in Windows and there shouldn't be any trouble.
|
# ¿ Jul 6, 2009 00:49 |
|
SlightlyMadman posted:I've got a question about many-to-many relationships. In the following model: How do you want the user associated to these models? Do you want the publication as a whole being attached to the user, or are individual pages of a publication written by different users? The first means putting User on Publication. The second means putting user on the Page model. After that, you have two options, you can either put Page as a M2M field on the Publication model, or you can put Publication as a Foreign Key on the Page Model.
|
# ¿ Jul 29, 2009 21:56 |
|
Jabab posted:
If you want to avoid raw sql, I believe you can name the child's ptr as such: code:
code:
http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns Basically it would look something like this in your template code:
|
# ¿ Mar 12, 2011 17:09 |
|
|
# ¿ Apr 30, 2024 04:47 |
|
quote:Is there a one liner for: adding to a python dict object is just as easy as you thought code:
|
# ¿ Mar 13, 2011 18:21 |