django

Djapian - filtering results

I use Djapian to search for object by keywords, but I want to be able to filter results. It would be nice to use Django's QuerySet API for this, for example: if query.strip(): results = Model.indexer.search(query).prefetch() else: results = Model.objects.all() results = results.filter(somefield__lt=somevalue) return results Bu...

Problem loading custom template tags (Error: No module named x)

Hi All, I am currently writing a few custom template tags but for some reason they will not load. My directory structure is as follows: MyProj | ----MyApp | |----templatetags | |----myapp_tags.py |----__init__.py In myapp_tags.py from django.template import Library, Node from myproj.myapp.mo...

Django error : Truncated incorrect DOUBLE value: 'AnonymousUser'

Hi guys, i dont know what mean this error, the erro comming when im try to enter to the admin ..webapps/django/lib/python2.5/django/db/backends/mysql/base.py:84: Warning: Truncated incorrect DOUBLE value: 'AnonymousUser' and another error is : "403 Forbidden Cross Site Request Forgery detected. Request aborted." somebody know about...

python PIL - background displayed opaque instead of transparent

I want to generate 32x32 sized thumbnails from uploaded images (actually avatars). To prevent a thumbnail from being smaller than that size, I want to create a transparent 32x32 background and paste the thumbnail on it. The code below tries to do so. However, the avatar is displayed on a black and opaque background; I lose transparen...

Django SESSION_COOKIE_DOMAIN error

Im trying to using SESSION_COOKIE_DOMAIN, but i got error in any browser when i try to go into my admin: Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again. any idea? ...

How do I use PyMock and Nose with Django models?

I'm trying to do TDD with PyMock, but I keep getting error when I use Nose and execute core.py from command line: "ERROR: Failure: ImportError (Settings cannot be imported, because environment variable DJA NGO_SETTINGS_MODULE is undefined.)" If I remove "from cms.models import Entry" from the unit test module I created, everything work...

DateFormat in Django and App Engine?

I have a slight issue with dates in Django and Google App Engine: I have the following class because I want date input in the form of DD/MM/YY: class MyForm(ModelForm): mydate = forms.DateTimeField(input_formats=['%d-%m-%y', '%d/%m/%y']) class Meta: model = MyObject This works for entering into the datastore....

Putting in extra restrictions when filtering on foreignkey in django-admin

When getting members based on Unit, I only want to get the ones who are actually in that unit as of now. I've got a model looking like this: class Member(models.Model): name = models.CharField(max_length=256) unit = models.ManyToManyField(Unit, through='Membership') class Membership(models.Model): member = models.ForeignKe...

Resize image twice in Django using PIL

I have a function in which I'm trying to resize a photo twice from request.FILES['image']. I'm using the image.thumbnail() with the Parser as well. This works fine when I create one thumbnail, but in my view if I repeat the exact same thing again, it fails in the parser via IOError cannot parse image. I'm very confused. I've created Stri...

Get django-paypal working with pycrypto?

I would like to use the button encryption in django-paypal, but it requires M2Crypto which will not build on webfaction servers. Tech support at Webfaction told me that pycrypto is already installed on the system, but I am too dumb to translate from M2Crypto to pycrypto. Can anyone tell me how to convert the following to work with pycr...

Django template dir switching

Does anyone know a way to switch the TEMPLATE_DIR in django dynamically. I need to create a set of templates for a mobile version and would like the templates to sit inside there own dir instead of inside the root template dir ie: I would like 2 template dirs 'templates' and 'mobile_templates' and not have to use 'templates/mobile' for ...

Is switching from PHP to Python worth the trouble

If you had switched from php + (framework of choice) to python + (framework of choice) as your development platform, what would you say have been the upsides/gains of the switch? What I want to know is if there were any significant improvements in the following aspects: Speed of development Maintainability of the finished solutions ...

Should Django be used for large, complex sites?

I've recently used Django for a very small CMS-style website. I was so impressed with how quick and easy it was to develop a Django project, that I'm now considering using it for a significantly larger project. However, before I get excited about the idea, I just wanted to run it by someone who actually has developed a very large Django...

How to conditionally skin an existing site (for partner branding)

I've got an existing Django site, with a largish variety of templates in use. We've agreed to offer a custom-skinned version of our site for use by one of our partners, who want the visual design to harmonize with their own website. This will be on a separate URL (which we can determine), using a subset of the functionality and data fr...

Django : How do I call "reverse" on a link to a static image file?

In Django, I have images stored in site_media like this : /site_media/somepath/image.jpg The urls.py file has been set up to server these using : urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'staticfiles.views.serve') ) urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'staticfiles.views.serve') ) So...

save method in a view

I have a very simple model: class Artist(models.Model): name = models.CharField(max_length=64, unique=False) band = models.CharField(max_length=64, unique=False) instrument = models.CharField(max_length=64, unique=False) def __unicode__ (self): return self.name that I'm using as a model form: from django.forms import ModelForm...

Testing feed generators in Django doesn't load attribute templates?

I extended django.utils.feedgenerator.Atom1Feed for my own needs and am trying to write some tests for it. It works fine from runserver and mod_wsgi. Basically, when feeds are accessed from the testrunner I'm running into these problems: 1) The item_title() and item_description() methods are never called, but item_pubdate(), item_link(...

what happen with this django-template if tag ?

Sorry if I am being a moron, but what happen with this if tag ? view return: return render_to_response('productos/por_estado.html', {'productos':productos}, context_instance=RequestContext(request)) #Im not returning 'estado' ! template: {% if estado %} {% block activos_active %}class="active"{% endblock %} {% en...

Migration to GAE

What is the best way to migrate MySQL tables to Google Datastore and create python models for them? I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a model for the table manually i...

Django inclusion tag with configurable template

I've created an inclusion tag, however I'd like to be able to make the template optionally configurable. There doesn't seem to be support for this out of the box, so I'd like to see how people did this - maybe a method search the templates directory first for a specific template name and then falling back to the default template. @regis...