|
I haven't used flatpages, but I take it it has a catch-all url? I wrote an app a while ago with a url redirector in it that had a catch-all, and didn't notice I'd included another module in my main urls.py below that one. So yeah, I've done pretty much the same thing before too.
|
# ? Dec 23, 2009 17:39 |
|
|
# ? May 17, 2024 16:44 |
|
LuckySevens posted:I'm a moron. I just spent 2 hours trying to get a custom comment system preview to display properly. I couldn't work out why it was giving me a 404. I tried everything, even ported it into another project and somehow it worked there. I made a post here with all the info, and it wasn't until I was seconds away from posting that I saw it.
|
# ? Dec 23, 2009 18:00 |
|
So far, I'm loving this framework, it's ridiculously easy to create a website, no matter how complex. I am having an issue though. I'd like to serialize an object returned from my database into json format. I've got that figured out using the serializers class. But I have a foreign key that I'd like to translate and have inserted in the final json object. I thought annotations would be perfect for this but I can't seem to annotate on a foreign key. Does anyone have an example of how I can do this?
|
# ? Dec 24, 2009 02:11 |
|
http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers Should help with serializing related models.
|
# ? Dec 24, 2009 02:34 |
|
king_kilr posted:http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers I've used this, and it's pretty good. You'll get a few errors: one I remember was about him using the 'newforms' name instead of just 'forms' - probably because it was written before 1.x - but it's literally just a case of a quick edit to the source to make it sensible again. Oh, and the JSON format's a little weird, but easy enough to figure out from looking at it.
|
# ? Dec 24, 2009 06:24 |
|
king_kilr posted:http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers I hope this becomes a part of the main branch because it's loving awesome. Thank you so much!
|
# ? Dec 24, 2009 07:30 |
|
Is it possible to filter by the ManyToMany fields? Suppose I have a Pizza model and a Topping model. Topping has a ManyToManyField pointing to Pizza. I now have an instance of a Pizza called mypizza. I would like to now search for all Pizzas with the EXACT same Toppings as mypizza. Intuitively it would like something like this: Pizza.objects.filter(toppings=mypizza.toppings_set) This, naturally, does not work. Any ideas? I'm happy to do some fancy black magic with the models to make it work, or do a custom SQL clause. I just don't know enough SQL to do that. Thanks!
|
# ? Dec 27, 2009 09:21 |
|
After reading the docs you'll probably come up with something like Pizza.objects.filter(toppings__in=mypizza.toppings_set.all())
|
# ? Dec 27, 2009 11:35 |
|
I tried that. IN does not mean two sets are equal. Or, to be snarky: After reading the docs you'll find that the IN operator does not do what I want.
|
# ? Dec 27, 2009 11:57 |
|
sink posted:I tried that. IN does not mean two sets are equal. If I were you, I'd just make a function that makes a string representation of the toppings, something that outputs something like "6532,1245,472,124" (the pk's of the toppings objects), and then call that function in the save() method, and store it in a CharField. Then you can just do: Pizza.objects.filter(toppings_flat=mypizza.flatten_toppings())
|
# ? Dec 27, 2009 13:40 |
|
This seems like a good idea but it just ... feels wrong. As though it were contrary to the way relational databases should be used. Am I stupid in thinking this way? Is this a common practice? My database architecture skills are very lacking. Thanks! I might try it.
|
# ? Dec 27, 2009 14:15 |
|
sink posted:This seems like a good idea but it just ... feels wrong. As though it were contrary to the way relational databases should be used. Am I stupid in thinking this way? Is this a common practice? My database architecture skills are very lacking. Thanks! I might try it. well, if theres no way to do it with the django ORM, then you have no other choice. This technique is called "denormalization" and will actually be a lot faster than doing the join, especially if you'll be doing a lot of these queries.
|
# ? Dec 27, 2009 15:06 |
|
Yeah, if I were custom coding something like that, that's probably exactly how I'd do it. I can't think of any way to do it is SQL that would be nearly as fast.
|
# ? Dec 27, 2009 16:59 |
|
I feel pretty retarded that this wasn't so obvious to me. Extending my example where I am searching for pizzas with identical toppings to mypizza. I just need to find pizzas with the same number of toppings as mypizza and then make sure that all of the toppings in mypizza are in those result pizzas. While you still can't do this with the Django ORM it's not super hard to do with SQL in a single statement using COUNT and IN on the Django-created pizza_topping join table... I think.
|
# ? Dec 27, 2009 18:58 |
|
sink posted:I feel pretty retarded that this wasn't so obvious to me. You can do it with the Django ORM, and I seriously don't know what everyone else in this thread is suggesting, denormalization is not the solution here: code:
|
# ? Dec 27, 2009 19:28 |
|
it depends on how you have your database set up. If you have a few hundred thousand pizzas and more than a few hundred toppings, the above queryset will slow things down a lot. Me, personally, I try to avoid any kind of full-table annotate like that unless it's a query that only gets executed once a day or something. Also, "denormalization" isn't really the right word. You're not denormalizing all of your data, you're just denormalizing for that one query.
|
# ? Dec 27, 2009 20:51 |
|
king_kilr, Thanks! The annotate was the key. If efficiency becomes an issue I will try something else out. How common is it for you guys to optimize parts of your webapp outside of the ORM? It seems like Django's object model isn't always the most efficient or intuitive way to work with tables. Does anyone ever supplement the ORM with SQL Alchemy for particularly hairy transactions?
|
# ? Dec 28, 2009 11:04 |
|
nbv4 posted:it depends on how you have your database set up. If you have a few hundred thousand pizzas and more than a few hundred toppings, the above queryset will slow things down a lot. Me, personally, I try to avoid any kind of full-table annotate like that unless it's a query that only gets executed once a day or something. What? No it doesn't, at least not that annotate (Well, at least not on DB2, MySQL, PostgreSQL or Oracle, ymmv in MSSQL***). Unless your indexes are retarded. If you have a several million pizzas you'll have a different issue. As always the trick is to get django's query for the operation and index appropriately (I think this particular query might benefit from a compound index) after an EXPLAIN/ANALYZE. quote:Also, "denormalization" isn't really the right word. You're not denormalizing all of your data, you're just denormalizing for that one query. Denormalization is the correct word. Denormalization is not always done on your entire data set, but on some fields that. In this case it might be useful since pizza toppings don't change, but, again, you won't run into problems until the several millions, and even then I bet you'd have to do some fancy denormalization on other parts of your data set before this particular query becomes a problem. *** Specially not in DB2. And actually over time PostgreSQL and Oracle generate bitmap indexes on the fly too, so no index needed there. Pretty sure DB2 also does this. deimos fucked around with this message at 13:38 on Dec 28, 2009 |
# ? Dec 28, 2009 13:26 |
|
I've never needed to replace Django's ORM. Of course I also know the deep dark internals and don't mind messing down there when necessary. That being said I do find Django's ORM incredibly intuitive, I wouldn't love it so much if it didn't make me so happy. Malcolm Treddinick actually wrote a blog post on how to solve this issue, but his site is down ATM
|
# ? Dec 28, 2009 18:51 |
|
I'm trying to deploy with WSGI and am apparently an idiot. I've got a test WSGI script that will return an HTTP response just fine, but when I try to access my app I get 403'd. I've verified that filesystem perms are appropriate, and have verified that I can run the dev server on the production platform just in case some dependency was missing. When I call my Django WSGI on the command line it runs and exits clean after a couple of seconds. I think there must be something wrong with my Apache config. Here it is: code:
|
# ? Dec 29, 2009 04:36 |
|
Sock on a Fish posted:I got this working, but I'm not sure why it was broken. I moved the app out of the /home/django dir and all is now well. Perms were set 644/755 for everything in my app's directory.
|
# ? Dec 29, 2009 06:04 |
|
Did you get anything better in the error logs? My gut says that it was probably wsgi not able to write the socket in the directory, but I can't remember if that results in a ISE 500 or a 401.
|
# ? Dec 29, 2009 15:20 |
|
What are perms of the myapp and the /home/django directory? Many distros, when you create users, remove execute or read permissions on home directories. If /home/django was missing +x or /home/django/myapp was missing +x, the apache user wouldn't be able to change into that directory.
|
# ? Dec 29, 2009 17:27 |
|
bmoyles posted:What are perms of the myapp and the /home/django directory? Many distros, when you create users, remove execute or read permissions on home directories. If /home/django was missing +x or /home/django/myapp was missing +x, the apache user wouldn't be able to change into that directory. Ah, that probably would've been it then. I didn't think it mattered what the permissions of a directory many levels above my WSGI script were. Entry in error log was simply: code:
code:
|
# ? Dec 30, 2009 06:42 |
|
just a heads up yall, the djangocon videos have been finally posted here: http://djangocon.blip.tv/
|
# ? Jan 4, 2010 15:04 |
|
nbv4 posted:just a heads up yall, the djangocon videos have been finally posted here: http://djangocon.blip.tv/ Awesome! I've been waiting ages for those to surface. Django 1.2 alpha 1 looks excellent as well. Good times.
|
# ? Jan 7, 2010 12:42 |
|
So here's a funky kind of question... We're trying to segregate static media from dynamic media within our application (static being things that are deployed wholesale with the application, dynamic being things that can be managed through the Django admin). In order to do this, we created two new settings alongside MEDIA_URL and MEDIA_ROOT, RWMEDIA_URL and RWMEDIA_ROOT. In our models, we're creating a FileSystemStorage object: rwstorage = FileSystemStorage(location=settings.RWMEDIA_ROOT, base_url=settings.RWMEDIA_URL) and then using that in models that have file or image upload fields like so: class AvatarImage(models.Model): image = models.ImageField(storage=rwstorage, upload_to="images/avatar/") name = models.CharField(max_length=32) def __url__(self): return self.image Problem is, this doesn't allow for relative urls near as I can tell, as the FileSystemStorage class' function relies upon urlparse.urljoin, which requires a full URL (http://...) for its base URL, meaning I can't generate relative URLs, correct? Any ideas on how to get around this, or are we stuck assembling base_url as an absolute URL?
|
# ? Jan 12, 2010 18:41 |
|
Hmm, so it looks like all we had to do was append a trailing / to the MEDIA_URL and RWMEDIA_URL settings, and everything works. Means we'll have some funky double slashes in some constructed URLs, and it sounds like it might've broken one of our context handlers, but I think we can work around this for now.
|
# ? Jan 12, 2010 19:01 |
|
I'm having trouble getting my urls to read in a slug:code:
What am I doing wrong? *edit* Wait! When I put in the slug without the -, it at least matched up. How do I allow hyphens? *double edit* Nevermind, I got it. Had to change the w to [-\w] Doh004 fucked around with this message at 00:06 on Jan 14, 2010 |
# ? Jan 13, 2010 23:58 |
|
Sorry for the double post but I have another question. I've installed the django-tinymce and was able to implement it by changing my CharField to a HTMLField. I want to change the body/content of a flatpage to incorporate the TinyMCE. I'm pretty sure I could accomplish this by defining a FlatPageAdmin class and unregister the FlatPage and reregister it with said class, but which admin.py would I put this in? Can I make an admin.py outside of an individual app and just at my project root? What exactly would be the best/easiest way to do this? I've found a lot of tutorials online, but they're all really outdated and I don't fully trust them. Thanks.
|
# ? Jan 18, 2010 06:27 |
|
Doh004 posted:Sorry for the double post but I have another question. Yes, you can make an admin.py anywhere, and as long as it's processed (read: imported) you'll be ok. My solution would just be to add a flatpage_ext app with nothing but the admin.py, but that's me. Otherwise you're spot on about providing a new ModelAdmin for FlatPage.
|
# ? Jan 18, 2010 17:39 |
|
Anyone have a good guide to having multiple levels of user authentication? ie, premium account and free accounts? Or am I just missing the obvious documentation on it?
|
# ? Jan 19, 2010 08:02 |
|
LuckySevens posted:Anyone have a good guide to having multiple levels of user authentication? ie, premium account and free accounts? Or am I just missing the obvious documentation on it? Look at the section "Storing additional information about users" here: http://docs.djangoproject.com/en/1.1/topics/auth/ Or you could use permission groups.
|
# ? Jan 19, 2010 08:21 |
|
jesus how did i overlook groups, time for a coffee.
|
# ? Jan 19, 2010 08:44 |
|
I set up a site that uses an email address for a username, and while I know you're not supposed to do that, it vastly simplifies the registration process for the user, so I did it anyways. I have no real problems on the registration and login side, but I can't edit any accounts in the admin console, because I get validation errors. What's the right way to do this? I also need to alter the user model, since I've discovered the username is limited to 30 characters, and I've already had one user unable to register since he had a preposterously long email address. Would a better approach be to just leave it alone, and toss a random alphanumeric string in the username column upon registration, then override all the authorization methods to check against email instead of username? I can't tell if that's a cleaner solution, or just more of a hack.
|
# ? Jan 19, 2010 17:08 |
|
SlightlyMadman posted:I set up a site that uses an email address for a username, and while I know you're not supposed to do that, it vastly simplifies the registration process for the user, so I did it anyways. I have no real problems on the registration and login side, but I can't edit any accounts in the admin console, because I get validation errors. I've got this issue too, unfortunately on a live site. Is there any way we could hack around to disrupt the checking on the admin site?
|
# ? Jan 19, 2010 17:24 |
|
I did this: http://dpaste.com/hold/147468/ to be able to edit accounts with רזו in the usernames. Too tired to figure out if that's any use to you guys, but there you go.
|
# ? Jan 19, 2010 17:53 |
|
chips posted:I've got this issue too, unfortunately on a live site. Is there any way we could hack around to disrupt the checking on the admin site? I've got a site with this as well, although I have no idea if our admin works. You should just need to provide a custom authentication backend that auths by email instead of username.
|
# ? Jan 19, 2010 17:56 |
|
Mulozon Empuri posted:I did this: http://dpaste.com/hold/147468/ to be able to edit accounts with רזו in the usernames. Too tired to figure out if that's any use to you guys, but there you go. This looks like it could do the trick. Pardon if this is a stupid question, but where do I put that? Can I just drop it in my app's admin.py file, or do I need to put it somewhere special? Additionally, is there a place I can override the User model to increase its max length?
|
# ? Jan 19, 2010 18:08 |
|
|
# ? May 17, 2024 16:44 |
|
Mulozon Empuri posted:I did this: http://dpaste.com/hold/147468/ to be able to edit accounts with רזו in the usernames. Too tired to figure out if that's any use to you guys, but there you go. Cheers, that looks like about the right thing.
|
# ? Jan 19, 2010 18:10 |