|
I think this is a pretty basic question and I'm embarrassed I can't find the answer. I have a view for displaying a single blog post: code:
How do I get the primary keys of the posts that are before and after the current post? I guess I have to start with something like this: code:
|
# ? Jun 3, 2012 15:22 |
|
|
# ? Jun 1, 2024 04:53 |
|
edit: Better answer in next post, it uses the Primary Key as a tie breaker so it's more reliable. Dunno if this is the most efficient but you could go up and take the first and then down and take the first, ie Python code:
Python code:
edit: Haha, well there ya go, forgot about that. I'll leave this here anyway. Maluco Marinero fucked around with this message at 16:08 on Jun 3, 2012 |
# ? Jun 3, 2012 15:51 |
|
If you've got a non-null datetime field, you're in luck, Django's handled it for you with get_[next|previous]_by_[yourfield]
|
# ? Jun 3, 2012 15:58 |
|
Thanks both. I'm glad Yay's solution worked so I didn't have to try and understand yours Maluco.
|
# ? Jun 3, 2012 16:56 |
Are there any resources (like the Django Book) that explain how to use the class-based generic views and their templates? I'm stuck trying to override DetailView to add extra info to the view. EDIT: Nevermind, I ended up creating a view instead of using a generic one. lunar detritus fucked around with this message at 05:06 on Jun 4, 2012 |
|
# ? Jun 3, 2012 17:19 |
|
Sharktopus posted:Do you mean how would you represent this within python or how would you take user input for this? How to represent it in python/django (getting user input I figure would depend on how it's represented). I apologize for the low-level question, still very much learning this.
|
# ? Jun 4, 2012 00:42 |
|
Sparta posted:How to represent it in python/django (getting user input I figure would depend on how it's represented). How about a dict of lists? { 'a': [True, False], 'b': [True, False], 'c': [1, 2, 3], 'd': ['a', 'b', 'c'] }
|
# ? Jun 4, 2012 02:02 |
|
gmq posted:Are there any resources (like the Django Book) that explain how to use the class-based generic views and their templates? CBVs are really simple once you get down their basic API. But, sadly, there aren't good docs for it yet. code:
|
# ? Jun 4, 2012 19:15 |
|
MonkeyMaker posted:CBVs are really simple once you get down their basic API. But, sadly, there aren't good docs for it yet. Do not confound CBVs and G(eneric)CBVs, two different beasts altogether.
|
# ? Jun 4, 2012 19:24 |
|
Sharktopus posted:How about a dict of lists? I can make a model out of a dict? I don't know what will be in it beforehand.
|
# ? Jun 4, 2012 21:48 |
|
We need to know more about the problem you're solving before we can do anything. What is a switch? What will it do?
|
# ? Jun 4, 2012 21:50 |
|
deimos posted:Do not confound CBVs and G(eneric)CBVs, two different beasts altogether.
|
# ? Jun 4, 2012 21:54 |
|
hitze posted:Why are they getting rid of FBVs Because the Django developers are terrible at making good decisions.
|
# ? Jun 4, 2012 22:26 |
|
Sparta posted:I can make a model out of a dict? I don't know what will be in it beforehand. So you need a way to represent it as a Django Model. If you need the fieldnames or choice values to be searchable then it's a bit tricky. However, if you just need a place to store and retrieve I would just serialize with whatever format you want (JSON, BSON, pickle) and stick it into a textfield. You should write some methods on the model to get and set and handle the serialization for you. Then you can define a property and just get/set the dict right on the model. This will also easily let you change serialization formats or storage method in the future.
|
# ? Jun 5, 2012 00:58 |
|
hitze posted:Why are they getting rid of FBVs They're not. They're getting rid of the existing generic function-based views. You can write all the if-filled function-based views you want.
|
# ? Jun 5, 2012 01:13 |
|
I'm working on a project for fun and I have a model in particular:Python code:
For viewing I have a view function that does a lot of the heavy lifting like steps 2-3 and packages this stuff into a custom data type that I have a custom templatetag pick up and parse. Now I find myself thinking about the editing part, where I'd like to have all of this be a form where you can edit the values for a month. I could do a formset of formsets thing for the month-week-codes, but this sounds like an awful lot of repeating myself. Should I load up the ChargeEntryManager with some custom functions to return packages of data in the format I need? I'm really having trouble wrapping my head around a container for all of these objects that I will eventually be slicing different ways... while not repeating myself and not making redundant queries to the db.
|
# ? Jun 5, 2012 04:52 |
|
I am having a weird problem on dotCloud, and I don't know if the fault is theirs or mine. One of the symptoms is that the static files don't work in 500 templates, whereas they do for 404. For 500, the {{ STATIC }} variable gives me /css/style.css, instead of the defined /static/css.style.css. Path is fine in 404, not so in 500. Here are the two different templates; I don't think there is any logic about the two elsewhere in neither URLS.py nor views.py: code:
code:
Any idea what causes the error? I already get a database error, when I deploy on dotCloud, which is why I get the 500 error to begin with. ufarn fucked around with this message at 17:09 on Jun 7, 2012 |
# ? Jun 7, 2012 17:06 |
|
You don't get context processors in 500 responses* (so no MEDIA_URL, STATIC_URL, request etc), so mostly you want to avoid extending a template, and hard code "all the things" * This is partly because the context processor itself may be throwing the exception, and partly because all kinds of other things could be. Too many moving parts. Yay fucked around with this message at 18:13 on Jun 7, 2012 |
# ? Jun 7, 2012 18:08 |
|
Yay posted:You don't get context processors in 500 responses* (so no MEDIA_URL, STATIC_URL, request etc), so mostly you want to avoid extending a template, and hard code "all the things"
|
# ? Jun 7, 2012 19:56 |
|
Apparently I'm the only person who keeps running into Django gotchas. It's awesome when trying to use transactions means that Django drops any exception in the function on the floor. Welp.
|
# ? Jun 8, 2012 08:41 |
|
Suspicious Dish posted:Apparently I'm the only person who keeps running into Django gotchas. It's awesome when trying to use transactions means that Django drops any exception in the function on the floor. Welp. Yes, you're the unique snowflake that has run into a framework's warts, no one else ever has had issues with django ever. Solution Soon™. For development you can use this gist. deimos fucked around with this message at 16:24 on Jun 8, 2012 |
# ? Jun 8, 2012 16:21 |
|
Cross-posting from StackOverflow - http://stackoverflow.com/questions/10953548/. I'm having a problem similar to nbv4's: The difference is that his problem field, PosBase, is visible, but mine is not. It is a required field, so I populate it in a call to add_fields() and use the HiddenInput widget on it. But the form validation always fails because Django it assumes the formset is only partially filled out. I've been banging my head against this problem all day - is there a different way I should be handling this nested formset?
|
# ? Jun 8, 2012 20:07 |
|
deimos posted:Yes, you're the unique snowflake that has run into a framework's warts, no one else ever has had issues with django ever. I just seem to keep running into them every day, and I want to tear my hair out. How can anyone think this framework is a good idea if it makes you do you extra work to debug an issue like this? deimos posted:Solution Soon™. For development you can use this gist. Four years? Does nobody ever use transactions or something?
|
# ? Jun 8, 2012 23:02 |
|
Suspicious Dish posted:I just seem to keep running into them every day, and I want to tear my hair out. How can anyone think this framework is a good idea if it makes you do you extra work to debug an issue like this? In the four years I've done django development, I've never had to handle transactions manually. I've only ever seen it done as a hack to get around some other bug in the code base.
|
# ? Jun 8, 2012 23:31 |
|
how!! posted:In the four years I've done django development, I've never had to handle transactions manually. I've only ever seen it done as a hack to get around some other bug in the code base. Is the stupidity of ManyToManyField requiring a model to be in the database and to have a PK considered a bug to you?
|
# ? Jun 8, 2012 23:37 |
|
Suspicious Dish posted:Is the stupidity of ManyToManyField requiring a model to be in the database and to have a PK considered a bug to you? It may be a little annoying (and easy to work around), but what does that have to do with manual transaction management?
|
# ? Jun 8, 2012 23:59 |
|
I set up a transaction, create my model, set up M2M entries and all that, then validate the model afterwards (validation is complex which relies on a lot of things, so I can't effectively do it pre-creation) commit if successful, rollback if failed.
|
# ? Jun 9, 2012 00:08 |
|
Ok, hopefully this makes sense... In the template... Python code:
In the view... Python code:
When I take a look at the html generated by {{ form.id }} I now realize that this isn't the id of the object, it's the id django uses to keep track of the forms in its formset (something like <input type="hidden" name="myobj_set-1-id" value="2" id="id_myobj_set-1-id" /> for the 2nd form in the formset, note value="2"), essentially 'hiding' the id of the object. How should I handle this?
|
# ? Jun 9, 2012 22:15 |
|
if I'm not mistaken, you don't need to manually iterate over all the forms in a formset to delete them, that part is handled by formset.save()
|
# ? Jun 10, 2012 00:01 |
|
how!! posted:if I'm not mistaken, you don't need to manually iterate over all the forms in a formset to delete them, that part is handled by formset.save() Oh, drat...thanks!
|
# ? Jun 11, 2012 02:33 |
|
The Django Book is broken up into paragraphs, each of which has its own comments. How do you think they did that? I'd like to do something similar with some papers that are about 5000 words each. I've never really thought about how to deal with large volumes of text before. What would the database look like? Do you think each paragraph should be stored separately? How would I make sure they're in the right order? What about preserving italics, or even footnotes? Any general advice would be appreciated before I start fumbling towards a solution. fuf fucked around with this message at 12:31 on Jun 11, 2012 |
# ? Jun 11, 2012 12:00 |
|
Does anyone have any advice/articles/gists on how to do nested forms? Be it inline forms or whatever. Only dealing with one-to-many relationships.
|
# ? Jun 11, 2012 16:10 |
|
This is an old bug that has resurfaced: when I refresh my local runserver instance by pressing F5 three times, I get a huge database error. I think I caught the entire error message, but it's a huge mess. Would love of anyone could shed some light on this, because I haven't the faintest idea what caused this, and when it happened in my commit history: http://dpaste.com/757602/ It sounds a lot like this and this. ufarn fucked around with this message at 16:38 on Jun 11, 2012 |
# ? Jun 11, 2012 16:30 |
ufarn posted:This is an old bug that has resurfaced: when I refresh my local runserver instance by pressing F5 three times, I get a huge database error. I think I caught the entire error message, but it's a huge mess. Would love of anyone could shed some light on this, because I haven't the faintest idea what caused this, and when it happened in my commit history: Out of curiosity, do you have a Windows firewall running or Execution Prevention jumping in and blocking ports? Maybe some other sort of software security which is killing connections?
|
|
# ? Jun 11, 2012 19:57 |
|
Jo posted:Out of curiosity, do you have a Windows firewall running or Execution Prevention jumping in and blocking ports? Maybe some other sort of software security which is killing connections? Here's a much more readable dpaste of what happens on the Ubuntu computer: http://dpaste.com/759013/. EDIT: Sounds like this is a known problem:
ufarn fucked around with this message at 12:49 on Jun 13, 2012 |
# ? Jun 13, 2012 10:27 |
|
ufarn posted:EDIT: Sounds like this is a known problem: It doesn't seem like a DB error, seems like the naive implementation of the development http server having timing issue. If your requests take long enough it'll throw that error.
|
# ? Jun 14, 2012 20:16 |
|
A bunch of videos from djangocon europe 2012. I do love that they tape all the talks.
|
# ? Jun 15, 2012 12:21 |
|
Does anyone have any opinions of Mezzanine (https://github.com/stephenmcd/mezzanine) they could share? Obviously I'll install / try it out, but if the mere mention of it makes you all recoil in horror, I'll save that time =)
|
# ? Jun 17, 2012 18:19 |
|
Just starting out using crispy-forms, it's a pretty cool form handler, although I am overloading the templates for it so I can control my display a little more. Forewarning, I was having a dumb moment where I just couldn't figure out whether it was actually reading from the template I thought it was. I was deliberately breaking the template and it would throw exceptions, but then when I was rendering it properly it wasn't showing my changes. Turns out crispy-forms caches the templates, had to reload the dev server to see changes. Don't code tired, otherwise you waste ages chasing stuff like this.
|
# ? Jun 18, 2012 13:29 |
|
|
# ? Jun 1, 2024 04:53 |
|
So I just started learning this stuff and I'm new to apache/webservers in general. I read and wrote up the django tutorial app on their website, the one that makes a simple admin interface and lets you create polls. I want to eventually put stuff out on a webserver so I made a VM using the bitnami djangostack and copied the tutorial app over there. Everything is working correctly except the actual poll details and results page. The index of polls works, but when you click a poll I get a "URL not found" error although the same code works perfectly using the internal test server on my regular pc. This is the error that apache puts in the log: code:
edit: Nevermind I figured it out... It was as obvious as I suspected I had my wsgi alias set as /mysite /directory/path after following the djangostack quick start guide and bumming their .conf and .wsgi files for my purposes. I changed it back to / /directory/path and boom! I really need to read up more on this stuff before jumping in. Master Stur fucked around with this message at 02:36 on Jun 19, 2012 |
# ? Jun 18, 2012 23:57 |