django

Why do I get this error when I run manage.py validate?

Why do I get this error when I run manage.py validate?: Traceback (most recent call last): File "manage.py", line 11, in <module> execute_manager(settings) File "C:\python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager utility.execute() File "C:\python26\lib\site-packages\django\core\...

Can I count on the order of field validation in a Django form?

I have a Django form with a username and email field. I want to check the email isn't already in use by a user: def clean_email(self): email = self.cleaned_data["email"] if User.objects.filter(email=email).count() != 0: raise forms.ValidationError(_("Email not available.")) return email This works, but raises some...

Select from dynamic table names

Hello pals, So here's the problem statement, SELECT app_label || '_' || model as name from django_content_type where id = 12; name ------------------- merc_benz DJango people might have guessed, 'merc_benz' is a table name in same db. I am writing some complex SQL migrations and I need to select result from such dyn...

how to move all those imports to standalone file

Imagine situation: I have view directory with tons of different views. all views have about 6 lines with imports - in the beginning of the file. it's pretty damn hard copy paste those 6 lines every time I create new view. I usually using all those imports. from django.contrib.auth.models import User from django.contrib.auth.decorator...

How to Access all the fields that have been filtered in a Django Custom Manager

Hi, I am writing a custom manager, and implementing the get_query_set method. Basically, I want to see that certain fields are passed into the query, think the Custom Site Manager but not wanting to add filters I want to ensure that some fields ARE filtered on. Below is one way, but I was wondering if there is a better way to get the f...

Django: union of different queryset on the same model

I'm programming a search on a model and I have a problem. My model is almost like: class Serials(models.Model): id = models.AutoField(primary_key=True) code = models.CharField("Code", max_length=50) name = models.CharField("Name", max_length=2000) and I have in the database tuples like these: 1 BOSTON The new Boston ...

Can I use Django F() objects with string concatenation ?

I want to run a django update through the ORM that looks something like this: MyModel.objects.filter(**kwargs).update(my_field=F('my_other_field')+'a string') This causes MySQL to throw an exception. Is there anyway to do this without writing raw SQL? ...

Django-profiles custom create/edit modelForm not saving properly

Summary: u = self.instance.user in def save(self, *args, **kwargs): u = self.instance.user u.first_name = self.cleaned_data['first_name'] u.last_name = self.cleaned_data['last_name'] u.save() return super(ProfileForm, self).save(*args, **kwargs) is causing a problem because self.instance doesn't exist. But yet this is how...

Django multi-model: tracing relationships

I have a multi model with different OneToOne relationships from various models to a single parent. Consider this example: class Place(models.Model): name = models.CharField(max_length=100) address = models.CharField(max_length=100) ... class Restaurant(models.Model): place = models.OneToOneField(Place) ... class Sh...

Writing file line to Django model field

I can't seem to write a line from a file to a field of a Django model. The field is described in the model as: text = models.TextField(null=True, blank=True, help_text='A status message.') However, when I attempt to create a new object I cannot fill this field using the readline function: file = open(filename, 'r') str = file.readli...

What this line doing? Django-template.

Explain me please what this line doing: <a href="{% url video.media.views.channel_browse slug=slug%}">Archie Channel</a> Actually this: {% url video.media.views.channel_browse slug=slug%} I know that it give me URL, but what from, or how it is making this URL? does this url depend from context? if it depend from context so which c...

Celery - Get task id for current task

How can I get the task_id value for a task from within the task? Here's my code: from celery.decorators import task from django.core.cache import cache @task def do_job(path): "Performs an operation on a file" # ... Code to perform the operation ... cache.set(current_task_id, operation_results) The idea is that when I c...

Authentication in Facebook Canvas App using New Graph API

Hello, I am building a Facebook canvas application that loads in an iframe with Django. I would like the login process to work similarly to the way Zynga does it. In this method, if you are not logged in you are redirected to a Facebook login page and then to a permissions request page for the app (without any popups). As far as I can...

right way to catch a race condition with Django ORM + MySQL/InnoDB

One part of my application has a race condition where multiple threads could end up creating the same persistent object. So I have implemented code that looks like this: from foobar.models import Bar def testomatic(request): bar = None tries = 0 while not bar: try: bar = Bar.objects.get(b=2) ex...

how to loop through httprequest post variables in python

How can you loop through the HttpRequest post variables in Django? I have for k,v in request.POST: print k,v which is not working properly. Thanks! ...

Writing authentication system

I am currently writing the backend for a service which has 3 clients: browser, android native and iphone native. I am having a little trouble with coming up with an authentication system since I don't know what can really be done on the clients. I am using django + twisted for the backend. Basically, I am going to be writing RestfulAPI...

Php-Django Chimera: is it possible?

I've seen a lot of posts about switching from php to Django but none have covered this. I have a website that is built entirely in php (php 5, mysql, and apache2). This site is used only for collecting data from users. Now I need to make a second half of the site to display the data. This will be step 2 of 5 in the overall plan, and I'd ...

Why is Django template feature breaking my page rendering?

To explain, I've taken a bare bones view from the tutorial of Django, and pointed it at an html page that I know works. When I do the following call: return render_to_response('index.html', {'stuff': 'blah'}) The resulting page is terribly broken in the sense that a lot of the styles are totally lost. However when I view the page sour...

Strange issue when trying to set a BooleanField value in a django model

I'm trying to change the value of a BooleanField in one of my models, but Django won't let me. Here's the relevant code: query = MyModel.objects.filter(name='example').filter(boolField=False) print query[0].boolField query[0].boolField = True query[0].save() print query[0].boolField This surprisingly prints: False False Any idea wh...

Which solution is better for Django social authentication?

django-socialregistration or django-SocialAuth? For my new project, I'm thinking of having signups only through Facebook (and possibly Twitter). Don't care about OpenID, hence this question doesn't answer my concern: http://stackoverflow.com/questions/2123369/whats-the-best-solution-for-openid-with-django Both these apps seem appropria...