django

Django, jQuery, XMLHttpResponse error

I'm trying to learn some basic ajax using Django. My simple project is an app that randomly selects a Prize from the available prizes in the database, decrements its quantity, and returns prize.name to the page. I'm using jQuery's $.ajax method to pull this off. The the only thing that's running is the error function defined in my $.a...

How to limit the maximum value of a numeric field in a Django model?

Django has various numeric fields available for use in models, e.g. DecimalField and PositiveIntegerField. Although the former can be restricted to the number of decimal places stored and the overall number of characters stored, is there any way to restrict it to storing only numbers within a certain range, e.g. 0.0-5.0 ? Failing that, ...

django template includes

I'm having an issue with django templates at the moment. I have 3 template files basically: Base story_list story_detail Story_list and _detail extend Base, and that works perfectly fine. However, list and detail share some code that extend the base template for my sidebar. I'm basically repeating a chunk of code in both templates, a...

Object label in GAE Django

In my usual django code I use the unicode function to give each object a label...this appears in the admin interface as the oject label in the objects listed... class apprd(models.Model): usr = models.ReferenceProperty(User) approved = models.BooleanProperty(default = True) def __unicode__(self): return ('approved one') ...

Retrieving key from new object created from create_object using Django generic views

My code looks as such: def add_cart(request): return create_object(request, form_class=CartForm, post_save_redirect=reverse('test.views.show_cart', kwargs=dict(object_id='%(key)s'))) Ideally, I would like it to look like so: def add_cart(request): newobject = create_object(request, form_clas...

What's the most efficient way to insert thousands of records into a table (MySQL, Python, Django)

Hello, I have a database table with a unique string field and a couple of integer fields. The string field is usually 10-100 characters long. Once every minute or so I have the following scenario: I receive a list of 2-10 thousand tuples corresponding to the table's record structure, e.g. [("hello", 3, 4), ("cat", 5, 3), ...] I nee...

multiple files upload using same input name in django

hello there, i m having trouble in uploading multiple files with same input name: <input type=file name="file"> <input type=file name="file"> <input type=file name="file"> at django side print request.FILES : <MultiValueDict: {u'file': [ <TemporaryUploadedFile: captcha_bg.jpg (image/jpeg)>, <TemporaryUploadedFile: 001_using_git_wi...

help needed for facebook api and django

hi, I am trying to get status msg of the user in my facebook app. But getting error in loading page. here is the code: user, created = FacebookUser.objects.get_or_create(id = request.facebook.uid) key = request.facebook.session_key some = request.facebook.friends.get() status_msg = request.facebook.status.get(request.facebook.uid) fr...

Django -- User.DoesNotExist does not exist?

I'm trying to get hold of Django. I use Pydev on Eclipse. I have written a simple signup page that I can't get to work. Eclipse complains that User.DoesNotExist is undefined. Most likely, I am missing something trivial. Here's the relevant portion of the code: from django.contrib.auth.models import User ... class SignUpForm (forms.Form)...

Django ImageField issue

I have a similar model Class Student(models.Model): """A simple class which holds the basic info of a student.""" name = models.CharField(max_length=50) age = models.PositiveIntegerField() photo = models.ImageField(upload_to='foobar', blank=True, null=True) As we can see photo field is optional. I wanted all the students who have the...

How to dynamically compose an OR query filter in Django?

From an example you can see a multiple OR query filter: Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3)) For example, this results in: [<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>] However, I want to create this query filter from a list. How to do that? e.g. [1, 2, 3] -> Article.obj...

How to dynamically compose an OR query filter in Django?

From an example you can see a multiple OR query filter: Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3)) For example, this results in: [<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>] However, I want to create this query filter from a list. How to do that? e.g. [1, 2, 3] -> Article.obj...

Django ORM: Selecting related set

Say I have 2 models: class Poll(models.Model): category = models.CharField(u"Category", max_length = 64) [...] class Choice(models.Model): poll = models.ForeignKey(Poll) [...] Given a Poll object, I can query its choices with: poll.choice_set.all() But, is there a utility function to query all choices from a set of...

How can you migrate Django models similar to Ruby on Rails migrations?

Django has a number of open source projects that tackle one of the framework's more notable missing features: model "evolution". Ruby on Rails has native support for migrations, but I'm curious if anyone can recommend one of the following Django "evolution" projects: South django-evolution dmigrations ...

How should I store state for a long-running process invoked from Django?

I am working on a Django application which allows a user to upload files. I need to perform some server-side processing on these files before sending them on to Amazon S3. After reading the responses to this question and this blog post I decided that the best manner in which to handle this is to have my view handler invoke a method on ...

Django - Manipulating list of lists in view

I have function in model, which returns a list of lists - [[a1,a2],[b1,b2]].I am passing this to view.But, how do I access each value.I want to display a1,a2,b1 and b2 separately. ...

Do I need PyISAPIe to run Django on IIS6?

It seems that all roads lead to having to use PyISAPIe to get Django running on IIS6. This becomes a problem for us because it appears you need separate application pools per PyISAPIe/Django instance which is something we'd prefer not to do. Does anyone have any advice/guidance, or can share their experiences (particularly in a shared W...

Problems with contenttypes when loading a fixture in Django

I am having trouble loading Django fixtures into my MySQL database because of contenttypes conflicts. First I tried dumping the data from only my app like this: ./manage.py dumpdata escola > fixture.json but I kept getting missing foreign key problems, because my app "escola" uses tables from other applications. I kept adding addition...

Using string literals as parameters to template tags in Django templates

One of the things I find myself doing often is passing string literals as parameters to template tags or functions; for instance: {% url my-url 'my_param' %} Unfortunately, the django template engine doesn't let you do this. So I find myself doing this a lot in my view code: my_context_dict['MY_PARAM'] = 'my_param' and then in my ...

Django BooleanField as radio buttons?

Is there a widget in Django 1.0.2 to render a models.BooleanField as two radio buttons instead of a checkbox? ...