django

Django model form using forms.ModelMultipleChoiceField

Hi - I have a ModelForm in my Django app that uses a forms.ModelMultipleChoiceField, which displays as a forms.CheckboxSelectMultiple widget on the form. This ModelForm is used to select/de-select values for a many-to-many relation. Here's the problem: when you uncheck all of the checkboxes and save the form, it doesn't save. If you un...

Django: accessing ManyToManyField objects after the save [Solved]

This is baffling me... When I save my model, the book objects are unchanged. But if I open the invoice and save it again, the changes are made. What am I doing wrong? class Invoice(models.Model): ... books = models.ManyToManyField(Book,blank=True,null=True) ... def save(self, *args, **kwargs): super(Invoice, sel...

Handling Image Uploads in Django

I have this view for my form: if request.method == 'POST': vehicle = VehicleForm(request.POST or None) photos = PhotosFormSet(request.POST or None) if vehicle.is_valid() and photos.is_valid(): new = vehicle.save() photos = PhotosFormSet(request.POST, instance=new) photos.save() return HttpResp...

How do I update my version of Django?

I currently have it installed and it's running a website. http://www.djangoproject.com/download/ This is the new version. How do I upgrade it? (How do I install the new version over my current one?) ...

What is the best OAUTH/Django library?

I use pyFacebook (which is not oauth) for facebook/django. What about oauth? What library do you guys absolutely recommend? I'm trying to implement a login system for LinkedIn: http://developer.linkedin.com/docs/DOC-1008#Authorization_in_the_LinkedIn_APIs ...

how to use array in django

Hi , I have a db table which has a integer array.But how can i add this field in my model .I tried writing it using IntegerField but on save it is giving error int() argument must be a string or a number, not 'list how can i add this field to my model.I m using this field in my views.py so i need to add it inmy model.Any suggestions...

open flash chart in python/django

I am using open flash chart for chart development. I need to put my image in the chart as in this example. I am using python for the development, and I can't find help anywhere about it. Can anyone give me an example with the created json so that I can create for my own charts. ...

What does pk__in mean in Django?

Model.objects.filter(pk__in=[list of ids]) and Model.objects.filter(pk__in=[1,2,3]) How do I show this data in a template? def xx(request): return HttpResponse(Model.objects.filter(pk__in=[1,2,3])) ...

Django, filtering the most recently added element

I want to retrieve the most recently added element and if there is none at all, assign some default values such as: query = X.objects.filter(name="aa",type="b")[0] if query: resultname =query.name resulttype = query.type else: resultname = "a default name" resulttype = "a default type" This is not working as it will ra...

Problem writing a database query

I have two models, Location and Event, that are linked by ForeignKey on the Event model. The models break down as follows: class Location(models.Model): city = models.CharField('city', max_length=25) slug = models.SlugField('slug') class Event(models.Model): location = models.ForeignKey(Location) title = models.CharFiel...

django error:connection to localhost;3312 failed ,i used django-sphinx.

Traceback (most recent call last): File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 280, in run self.finish_response() File "D:\Python25\Lib\site-packages\django\core\servers\basehttp.py", line 319, in finish_response for data in self.result: File "D:\Python25\Lib\site-packages\django\http\__ini...

How can my django model DateField add 30 days to the provided value ?

Hay guys, as the title suggests. I want to add 30 days to the DateField field. This is auto populated on creation of record using auto_now_add=True Any ideas how to go about doing this? Thanks ...

In Django, my request.session is not carrying over...does anyone know why?

In one view, I set: request.session.set_expiry(999) request.session['test'] = '123' In another view, I do: print request.session['test'] and it cannot be found. (error) It's very simple, I just have 2 views. It seems that once I leave a view and come back to it...it's gone! Why? ...

How to send a HTTP Header request rather than HTTP URL in Python.

I'm doing Oauth, and Linkedin needs me to send a "header" request instead of URL request (I have no idea what that means). This is what someone says on Google: If the library you are using isn't using HTTP headers for the authorization, you're not going to be able to access protected resources. Most OAuth libraries have an o...

Django: Using custom primary key, should I specifiy unique=True?

I read this page: http://www.djangoproject.com/documentation/models/custom_pk/, and the example doesn't list unique=True. I'm wondering if there is a compelling reason for them to leave it out, or if there is some reason I should include it. My assumption is that specifying primary_key=True does this automatically though. Any thoughts? ...

django many to many validation when add()

Hi i have a Category model with parent/child self relation For primary category and sub categories : class Place(models.Model): name = models.CharField(_("name"), max_length=100) categories = models.ManyToManyField("Category", verbose_name=_("categories")) class Category(models.Model): name = models.CharField(_("name"), ma...

Django: how to define two fields "unique" as couple

Is there a way to define a couple of fields as unique in Django? I have a table of volumes (of journals) and I don't want more then one volume number for the same journal. class Volume(models.Model): id = models.AutoField(primary_key=True) journal_id = models.ForeignKey(Journals, db_column='jid', null=True, verbose_name = "Jour...

How can I test a form's validation logic in a unit test driver in Django?

I want to test the is_valid portion of a form's validation logic. In my test driver I have: test_animal = Animal(name="cat", number_paws="4") test_animal_form = AnimalForm(instance=test_animal) assertEqual(test_animal_form.is_valid(), True) The assertion fails, but from what I see there shouldn't be any errors in the form. I...

Distinguishing parent model's children with Django inheritance

Basically I have a Base class called "Program". I then have more specific program model types that use Program as a base class. For 99% of my needs, I don't care whether or not a Program is one of the specific child types. Of course there's that 1% of the time that I do want to know if it's one of the children. The problem is that if I ...

how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST

I read this "DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every RequestContext will contain a variable request, which is the current HttpRequest. Note that this processor is not enabled by default; you'll have to activate it. " from this page http://docs.djangoproject.com/en/dev/ref/tem...