I'm working on a silly weekend project called, "The Best Picture" as a method of getting into Django again. I have TheBestPicture as the project, then apps for uploading, voting, and doing user management. These all share several common classes, notably Picture, Vote, and User. Where should I define models for these classes so that they are accessible to all the applications in the project? I hate to decide arbitrarily to put it in the Picture, Vote, or User apps, so I dumped the .py files for the objects in the main folder along with settings and the like. This is probably not the best idea since now the interpreter throws a poo poo fit if I do, Picture.objects.all(). tl;dr: Where should I define a model used across several applications in a project? EDIT: code:
Jo fucked around with this message at 01:16 on Aug 8, 2009 |
|
# ? Aug 8, 2009 01:11 |
|
|
# ? May 16, 2024 01:19 |
|
If you have a single model that needs to be a lot of places, you can put it in it's own app, and just import it everywhere you use it ("from picture.models import Picture"). Or if you have a bunch of models which are used all over the place, you can do what I do and just put them all in one app called "main", then instead ofcode:
code:
Theres actually a bug in django (that hasn't been fixed as of a few weeks ago at least), where django will poo poo itself if you define a model like this: code:
code:
|
# ? Aug 8, 2009 01:21 |
nbv4 posted:Words. Awesome. Thank you!
|
|
# ? Aug 8, 2009 01:45 |
|
Anyone have any experience with using Django with Google App Engine? For my first Django app, I'm writing a small webapp for my company. With app-engine-patch it's not too bad, as I get the admin interface, which was really great in selling my boss/coworkers on the project who otherwise couldn't care less about python webapps. Also it's completely free, which is nice in lean times. Working around some of the datastore limitations can be a bit annoying but overall it's been pretty alright.
|
# ? Aug 8, 2009 06:34 |
|
NerftheSmurf posted:Anyone have any experience with using Django with Google App Engine? For my first Django app, I'm writing a small webapp for my company. With app-engine-patch it's not too bad, as I get the admin interface, which was really great in selling my boss/coworkers on the project who otherwise couldn't care less about python webapps. Also it's completely free, which is nice in lean times. You also might want to look at: http://code.google.com/p/google-app-engine-django/ no idea if it's better or worse, but I know one of the devs
|
# ? Aug 8, 2009 06:59 |
|
Is anyone here able to get django_cropn and django-tagging to work in 1.1? I can get tagging to work, but if I try to register the Model with the tagging app, I get a "Can't Adapt" error whenever I try to add a new instance of that model. I wrote this up on the django group, but I got no response: http://groups.google.com/group/django-users/browse_thread/thread/68e58977b46d08bd/f7ce9ec1b56ef8a2?lnk=gst&q=nbv4#f7ce9ec1b56ef8a2 And In django_cron, I get this error when I try to run syncdb when "django_cron" is in my INSTALLED APPS": code:
|
# ? Aug 15, 2009 02:17 |
|
I need some ideas on how to populate an HTML table. This is what happens: 1) A driver is given a shift (a position number) for a day (done in the admin panel) 2) That number needs to be placed on a table, like so: This is what I have: http://parkrrr.net/bus/schedule/ I'm a bit lost as to how to synchronize the cells. I'm really quite lost on this so any help would be appreciated.
|
# ? Aug 17, 2009 02:31 |
|
Wow, this is driving me crazy, I hope someone can help. I am trying to use the dev server to serve up images from my media folder, and nothing I do seems to work. Here is how my settings.py looks: code:
code:
I have definitely imported os in both settings.py and urls.py and I am sure this is something simple. Please help!
|
# ? Aug 19, 2009 18:19 |
|
You can't have ADMIN_MEDIA_PREFIX and MEDIA_ROOT be the same.
|
# ? Aug 19, 2009 18:52 |
|
Man do I feel stupid. Thanks very much.
|
# ? Aug 19, 2009 20:20 |
|
I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible. It seems to me the best way to do this would be to create a custom field type, so I could do something like this in my model: image_tb = models.CustomImageField("Thumbnail Image", upload_to ='uploads/projects', size=(50, 50), compression="60", watermark="path/to/watermark.png") Firstly, I have absolutely no idea if this is the best way of doing things. Is it easier to create a custom field or perhaps hijack the save method? If it is the best method, does anyone have any really simple examples of creating a custom field? Most of the stuff online is incredibly complicated. Secondly, if I was to create a custom field, is there a way to extend ImageField so I don't have to mess with the admin panel code and keep the core functionality in place? Would really appreciate any help.
|
# ? Aug 20, 2009 22:08 |
|
Hanpan posted:I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible. http://www.djangosnippets.org/tags/image/
|
# ? Aug 20, 2009 22:23 |
|
Hanpan posted:I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible. Checkout sorl-thumbnail, it probably has everything you want in it: http://thumbnail.sorl.net/docs/
|
# ? Aug 20, 2009 22:38 |
|
I'm trying to use Django's formsets and having nothing but problems. Here's my current code for the validation/save view:code:
Any ideas?
|
# ? Aug 23, 2009 05:26 |
|
Whoa whoa whoa, you know you can just give a formset a queryset and be done with it.code:
code:
|
# ? Aug 23, 2009 05:35 |
|
Anyone have experience customizing the comments framework? I followed the doc on this page http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/ but I can't figure out to render my new CommentFormWithTitle. The documentation is kind of sparse (or this is way out of my league to be messing around with).
|
# ? Aug 23, 2009 19:09 |
|
nbv4 posted:Whoa whoa whoa, you know you can just give a formset a queryset and be done with it. Hey, thanks for this. It didn't actually solve my problem, but it pointed me at inlineformset, which did.
|
# ? Aug 24, 2009 17:44 |
Argh. I can't figure out why this is happening. I save an object and it doesn't show up in TheModel.objects.all():code:
|
|
# ? Aug 25, 2009 02:40 |
|
By any chance have you overridden the save method on your Appointment model without calling super(Appointment, self).save() ?
|
# ? Aug 25, 2009 03:04 |
jupo posted:By any chance have you overridden the save method on your Appointment model without calling super(Appointment, self).save() ? Not that I'm aware. code:
|
|
# ? Aug 26, 2009 03:20 |
|
Jo posted:Not that I'm aware. Try getting rid of the __init__ part. I think you may be overwriting something that is required. You can use the default kwarg in your model class to achieve what you want. like this: code:
Appointment(advisor="MyAdvisorAbbreviation", datetime="whatever")
|
# ? Aug 26, 2009 04:00 |
|
I was on the right track, technically the problem is you're not calling __init__ on the super class, but nbv4 is right in that you don't need any of that stuff there at all.
|
# ? Aug 26, 2009 07:02 |
|
Another absolutely retarded question: Is there a way to exclude fields form a query set? I am putting my result straight into JSON, and I am I trying to exclude a "tags" ManyToMany field from my model since I don't need it and it will hit the database unnecessarily. I have tried this: code:
|
# ? Aug 27, 2009 22:21 |
|
Hanpan posted:Another absolutely retarded question: http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields code:
|
# ? Aug 27, 2009 22:35 |
nbv4 posted:jupo posted:Thank you for the responses. If it works, I will love you fo evah. Edit: It works. Jo fucked around with this message at 22:11 on Aug 28, 2009 |
|
# ? Aug 28, 2009 21:47 |
|
I've been teaching myself django slowly by using it to make web interfaces for my various maintenance scripts and I'd like to hear what the best practice is for solving the following problem. I'm trying use SQLite full text search from django. I've been googling around and couldn't find anyone else doing it properly, most just used raw SQL statements or other database engines. SQLite's full text search implementation works via a special table that just maps search results to ids. That's not important, as the table isn't updated from django. If I need to do so I'll just use signals or make a SearchableModel subclass that overrides save(). The actual search is where I'm not sure how to do it best. Right now I've made a complex filter class that hacks in the required join (I don't know how to force a join in a good way) and adds the 'WHERE search_table.content MATCH ' + searchstring clause to the QuerySet. That's obviously not pretty and it's also vulnerable to injections, so is there a better way to extend QuerySet functionality? It hit me while writing this that I could add the search table as a managed table with a foreign key for the main table and then add support for a __match operator in the db backend, could I do this in a reusable way? Edit: I switched to Postgres and patched django-fts to suit my needs but if anyone else wants to do this with SQLite it's much easier to patch into django 1.1 than 1.0 Threep fucked around with this message at 22:09 on Sep 1, 2009 |
# ? Aug 28, 2009 22:26 |
|
I have to move my Django app over from Linux to Windows, and I'm having trouble serving up the admin media. The lines that are related to the issue are probably the following: From Apache httpd.conf: code:
code:
|
# ? Sep 2, 2009 21:57 |
|
Try thiscode:
|
# ? Sep 3, 2009 00:16 |
|
Also, try changing the media URL for your site to something other than http://localhost/media. You can't have admin media teh samne as regular media.
|
# ? Sep 3, 2009 00:50 |
|
jupo posted:Try this But if settings.MEDIA_ROOT is pointing at django/contrib/admin/media, would the admin media work? I figured since the project has no media, I would just point that at the admin media directory. If I made my own media directory, would I have to put the admin media in there? Also, I tried your suggestion out and it still doesn't work. Now I'm going to make a media directory inside my project and point MEDIA_ROOT at that. Edit: With the new Location section that you suggested, should I still have the Alias /media/ line in there? Edit again: So I added a clause to my urls.py that says if the settings file has DEBUG set to True, then have django serve the media files, and the admin media started working properly. Does this mean it's an issue with my Apache config? Another edit...: I have a Directory statement in my Apache config pointing to my project's media directory. If I take it out of the config, even with that statement in the urls.py and DEBUG set to True, Django does not serve the admin media. I'm confused about why that is. Also, I'm getting TemplateDoesNotExist errors in my Apache error log when going to http://localhost:/admin checkeredshawn fucked around with this message at 16:20 on Sep 3, 2009 |
# ? Sep 3, 2009 15:26 |
|
MEDIA_ROOT is used for Django-uploaded files. You don't really use it to tell Django where your media is located. You do use MEDIA_URL as a way to use the {{ MEDIA_URL }} variable throughout your templates though. Basically, to serve media from Apache you need to tell Apache to ignore your media directory as non-Python code, e.g: code:
Basically, when it comes down to it the MEDIA_ROOT variable is not used at all to serve media, just for upload paths. Apache/nginx/the Django devserver is in charge of serving the media by setting up the correct paths.
|
# ? Sep 3, 2009 18:28 |
|
bosko posted:MEDIA_ROOT is used for Django-uploaded files. You don't really use it to tell Django where your media is located. You do use MEDIA_URL as a way to use the {{ MEDIA_URL }} variable throughout your templates though. I've got a media directory in my project's root, which contains a folder called "admin" with all the admin media, but it still isn't working out. Could it have something to do with my sticking my project in C:\Python25 so that it would be on the python path? I was having issues with Apache when I was trying to declare PythonPath to contain my project's directory, so I just threw it in C:\Python25 and it started working. Edit: Okay, I put the media directory in the DocumentRoot folder, and now it works. Thanks for all the help everyone. I even moved the project out of C:\Python25 into a different directory (C:\django) and got the PythonPath thing working (I think it was because I had PythonPath "['C:\django'] + sys.path" as opposed to "[r'C:\django'] + sys.path", note the lowercase r in there). checkeredshawn fucked around with this message at 21:21 on Sep 3, 2009 |
# ? Sep 3, 2009 20:51 |
|
This is kind of an Apache/WSGI problem, but I'm trying to deploy Django, and I thought maybe someone here would have seen this before: I'm on WinXP and when I run net start apache I get the following error message in Event Viewer: code:
code:
|
# ? Sep 5, 2009 06:05 |
|
LOLLERZ posted:This is kind of an Apache/WSGI problem, but I'm trying to deploy Django, and I thought maybe someone here would have seen this before: Silly question but does the file exist?
|
# ? Sep 5, 2009 20:58 |
|
I'm 99% sure mod_wsgi does not come standard on Apache installs so he probably needs to install the module seperately. Not very familiar with Windows installation but this seems to be a good writeup: http://code.google.com/p/modwsgi/wiki/InstallationOnWindows
|
# ? Sep 6, 2009 02:05 |
|
deimos posted:Silly question but does the file exist?
|
# ? Sep 6, 2009 04:40 |
|
LOLLERZ posted:That's a perfectly reasonable question, but yes, I have the correct file for my major/minor version of Python, and for my install of Apache, and it's named correctly. It's in the same location as all the other mod_whatever.so files. well if you renamed it to mod_wsgi.so and placed it in the right directory then check windows permissions for the other .so files and compare it to your mod_wsgi.so
|
# ? Sep 6, 2009 06:41 |
|
deimos posted:well if you renamed it to mod_wsgi.so and placed it in the right directory then check windows permissions for the other .so files and compare it to your mod_wsgi.so
|
# ? Sep 6, 2009 06:57 |
|
I'm looking for a little advice on deploying some Django websites to an Ubuntu Server. Where exactly should each website live within the file structure? It seems wrong to put everything under my home folder. I realise there are probably lots of ways to do it, so is there any best practice? Similarly, is there any best practice for structuring the website and associated files? At the moment I've got everything organised on my desktop computer like this: code:
On the actual server, I imagine I want to apt-get Django rather than install it manually like I've done here. It was a few months ago and I'm not really sure why I did that. I'm also slightly concerned about whether my current structure is sensible for code reuse. I like to keep each website together for organisation and backup purposes but I'm sure I can adjust if this is a silly way to go about it. Any advice would be very much appreciated.
|
# ? Sep 7, 2009 19:31 |
|
|
# ? May 16, 2024 01:19 |
|
JammyB posted:I'm looking for a little advice on deploying some Django websites to an Ubuntu Server. This is one of the best guides I've read. Only thing I'd change is using virtualenvwrapper along with virtualenv. Oh, and I usually use MySQL instead of PostgreSQL. http://lethain.com/entry/2009/feb/13/the-django-and-ubuntu-intrepid-almanac/
|
# ? Sep 8, 2009 00:58 |