django

is it possible to define name of function's arguments dynamically?

Now I have this code: attitude = request.REQUEST['attitude'] if attitude == 'want': qs = qs.filter(attitudes__want=True) elif attitude == 'like': qs = qs.filter(attitudes__like=True) elif attitude == 'hate': qs = qs.filter(attitudes__hate=True) elif attitude == ...

What attributes should belong to a page and what should belong to a model?

Say you have an Events model that contains information about the event. But what about things like slugs, titles and meta description that would go into the html? It would seem like such things properly belong as attributes to a Page model rather than to an Events model. Is there a correct way to do this? What are the pros and cons of...

How to get publisher.authors when you have book.publisher and book.author?

Fresh from the Djangobook tutorial using the Books app example, you have Book related to Author through a many-to-many relationship and Book related to Publisher. You can get a set of books associated with a publisher with p.book_set.all(), but what do you need to do to get a set of authors associated with a publisher (through the books ...

Why is django slow to generate select boxes for foreign keys?

I have an admin view which contains four foreign keys each with a few thousand entries. It is slow to appear in the browser. If I change the django model to eliminate the select boxes by adding raw_id_fields things become nice and snappy. So the slowness is due to the population of the select drop downs and also this is a known issue s...

What are some successful methods for deploying a Django application on the desktop?

I have a Django application that I would like to deploy to the desktop. I have read a little on this and see that one way is to use freeze. I have used this with varying success in the past for Python applications, but am not convinced it is the best approach for a Django application. My questions are: what are some successful methods ...

What is the best way to redirect email to a Python script?

I'd like to provide a functionality for users of my website to get assigned an email address upon registration (such as [email protected]) but I don't really think it is feasible to actually support all these emails account normally through a webmail program. I am also not sure if my webhost would be cool with it. What I'd ...

django on Google Appengine

I came across 2 different modules for porting django to appengine. http://code.google.com/p/app-engine-patch/ http://code.google.com/p/google-app-engine-django/ Both seem to be compatible with django 1.0, The featured download of the latter is in Aug 08, whereas the former is Feb 09. What are the relative merits. What if I dont use...

In Django, how can I pre-populate an edit form from a model/child, but save submission as new instance?

I'm trying to prepopulate a ModelForm and an inlineformset_factory with an instance of a Model, BUT when the user submits the form, I need to create a new instance of the Model and it's related child records. Example Model: class Artist(models.Model): artist = models.CharField(max_length=100) class Song(models.Model): artist =...

How do I block people from intentionally re-submitting a form?

I'm building a website using Ubuntu, Apache, and Django. I'd like to block people from filling out and submitting a particular form on my site more than once. I know it's pretty much impossible to block a determined user from changing his IP address, deleting his cookies, and so on; all I'm looking for is something that will deter the ca...

Django: How can I identify the calling view from a template?

Short version: Is there a simple, built-in way to identify the calling view in a Django template, without passing extra context variables? Long (original) version: One of my Django apps has several different views, each with its own named URL pattern, that all render the same template. There's a very small amount of template code that...

Django serializer gives 'str' object has no attribute '_meta' error

Hello! I am trying to make Django view that will give JSON responce with earliest and latest objects. But unfotunately it fails to work with this error. 'str' object has no attribute '_meta' I have other serialization and it works. Here is the code. def get_calendar_limits(request): result = serializers.serialize("json", Sessi...

Database Reporting Services in Django or Python

Hi, I am wondering if there are any django based, or even Python Based Reporting Services ala JasperReports or SQL Server Reporting Services? Basically, I would love to be able to create reports, send them out as emails as CSV or HTML or PDF without having to code the reports. Even if I have to code the report I wouldn't mind, but the ...

retrieve bounding box of a geodjango multipolygon object

How can I get the bounding box of a MultiPolygon object in geodjango? Can't find anything in the API http://geodjango.org/docs/geos.html ... ...

Open Source Web Frameworks : Security

How secure are popular open source web frameworks? I am particularly interested in popular frameworks like Rails and DJango. If I am building a site which is going to do heavy e-commerce, is it Ok to use frameworks like DJango and Satchmo? Is security compromised because their open architecture ? I know being OS does not mean being...

How to store data in Django Model without having an input field

I have model for example like this: class Meeting(models.Model): date = models.DateTimeField(default=datetime.datetime.now) team = models.CharField(max_length=100) class Meta: verbose_name_plural = u'Meetings' ordering = ['-date', 'team'] def __unicode__(self): return u'%s %s' % (self.date, self...

Accessing MultipleChoiceField choices values

How do I get the choices field values and not the key from the form? I have a form where I let the user select some user's emails for a company. For example I have a form like this (this reason for model form is that it's inside a formset - but that is not important for now): class Contacts(forms.ModelForm): def __init__(self, *args...

Django view returns string which is not represented correctly in html template

A view I am using returns a string to a html template. The string which is returned contains special characters which are not represented correctly in the template. To put it simply a string which is returned from the view might look like this: test = "\"Foo bar\"" return render_to_response('index.html', {'test': test}) And is displ...

Django: want to use loop.counter to assign letter for Google Maps marker

I've got a variable number of items, somewhere between 0 and 20. I'd like to list these with Google Static Maps, showing a little "a" for the first one, a "b" for the second one and so on. I'm a newbie using Google App Engine so I'm constrained to 0.96 (unless I use various patches, which I don't want to do. Because I'm a newbie.) &m...

How to convert datetime to string in python in django

Hello, I have a datetime object at my model. I am sending it to the view, but in html i don't know what to write in order to format it. I am trying {{ item.date.strftime("%Y-%m-%d")|escape }} but I get TemplateSyntaxError: Could not parse some characters: item.date.strftime|("%Y-%m-%d")||escape when I am just using {{ item.date...

How to compare value of 2 fields in Django QuerySet?

I have a django model like this: class Player(models.Model): name = models.CharField() batting = models.IntegerField() bowling = models.IntegerField() What would be the Django QuerySet equivalent of the following SQL? SELECT * FROM player WHERE batting > bowling; ...