Monday, April 1, 2013

Re: Confusion about Static Files

These differences between debug and production mode are also a bit confusing. The site I am writing is not supposed to be very scalable; it is a very simple web application for internal use at my job that we aren't expecting to have more than a few users. It would only take me a few hours to code it in PyGTK, but we want to put it online so remote users can access the same database. It are only supposed to have a few pages and a few more static files, so setting up multiple servers seems unjustified. I will see if I can use a more standard solution for static files (I think it may be running on Apache), but if not, is there a more elegant way to serve static files through Django in production?

On Friday, March 29, 2013 4:02:30 PM UTC-5, BFSchott wrote:
David,

This took me a while to figure out also when I first started.  Running with debug on and runserver works great, then you try to use it in production and things break.  The big picture idea is that static files are intended to be hosted by something in front of Django, be that Apache or Ngnix or whatever.  All of the django.contrib.static module does is define a) how/where the manage.py collectstatic command finds static files, STATICFILES_FINDERS, STATICFILES_DIRS, b) where it will save them on the local filesystem STATIC_ROOT, and c) what URL prefix will get used in templates STATIC_URL.

With settings.DEBUG  = True, you can add static files to your url pattern with the code below so that your server will work with manage.py runserver, but as soon as you go production and turn off DEBUG, this will stop working by design.
---
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
---

You really want not to serve files through Django.  Just do a collectstatic before runserver, and point your web server /static/ location at that directory. Here is a link to the nginx.conf file used by Mezzanine (a Django CMS app).
Notice that location /static/ is served directly and everything else for the most part is a redirect to the Django server running on another port.  You can find Apache examples all over the place.  


Brian Schott



On Mar 29, 2013, at 3:36 PM, David Pitchford <david.t....@seagate.com> wrote:

I am experienced with Python but new to Django and web development in general. I am struggling to understand its static files system from the documentation. It seems like I have to set multiple settings variables and create multiple folders in order to get the server to accomplish the simple task of "finding" these files. After toying with it for a few hours I haven't been able to get the static files system to work and and have resorted to the following system which is probably a very bad idea:

In views.py:

from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
import datetime
import os.path
import settings

statictypes = {".css": "text/css",
               ".js": "text/javascript"}

def servestatic(request, filename):
    fullfilename = os.path.join(settings.STATIC_ROOT, filename)
    ext = os.path.splitext(filename)[1]
    return HttpResponse(open(fullfilename).read(), content_type=statictypes[ext])

And in urls.py:

from django.conf.urls import patterns, include, url
import mysite.views as views

staticextensions = [ext[1:] for ext in views.statictypes.keys()]
staticextstring = '|'.join(staticextensions)

urlpatterns = patterns('',
...
    (r"([^/]+\.(?:%s))$" % staticextstring, views.servestatic)
)

This actually works (and I could optimize it by caching the static file contents in memory rather than continually rereading them), but of course it's circumventing Django's built-in system for managing static files. My project architecture looks like this:

mysite
|
|--manage.py
|--mysite
   |
   |__init__.py
   |settings.py
   |urls.py
   |views.py
   |wgsi.py
   |--static
   |  |
   |  |--jquery.js
   |  |--TestFormat.css
   |
   |--templates
      |
      |--TestTemplate.html

At the beginning, the documentation page mentions, "For small projects, this isn't a big deal, because you can just keep the static files somewhere your web server can find it." This sounds like the simple solution I'm looking for; what does it mean and how do I do it? I'm also frequently confused by how when I created the project it created two nested folders with the same name. Which is considered to be the "project root"?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

How to create a form list for a Model Form dynamically?

I am trying to make a simple quiz app.

I am trying to go to the URL /quiz/<quiz_id> and using the quiz_id which has a list of questions associated with the quiz id and create a list of forms to use in the model form.

In the urls.py file I know you can pass a list of forms to be used, but I need to create the list of forms at runtime.

I have tried passing the return value of a function as parameter but can't figure out the syntax.

(r'^(?P<quiz_id>\d+)', QuizWizard.as_view(get_form_list)),  the function get_form_list has no length    (r'^(?P<quiz_id>\d+)', QuizWizard.as_view(get_form_list(quiz_id))),  Quiz_id is unknown.

So I create a view and I create the form list inside the view and then call QuizWizard.as_view

#views.py  class QuizWizard(SessionWizardView):      def __init__(self, **kwargs):          self.form_list = kwargs.pop('form_list')          return super(QuizWizard, self).__init__(**kwargs)        def done(self, **kwargs):          return render_to_response('done.html', {              'form_data':[form.cleaned_data for form in self.form_list],          })    def get_form_list(request, quiz_id):      quiz = Quiz.objects.get(id=quiz_id)        question_forms = []        for question in quiz.questions.all():                  choices = []          for choice in question.choices.all():              choices.append(choice)          f = QuestionForm(instance=question)                  question_forms.append(f)            #quiz_wizard = QuizWizard()      return QuizWizard.as_view(form_list=question_forms)(request)

But I am getting the error 
issubclass() arg 1 must be a class


My issue is syntax either way I can't figure out how to call the QuizWizard.as_view(). Here are related files:

#forms.py
class QuestionForm(forms.ModelForm):      class Meta:          model = Question

#urls.py
urlpatterns = patterns ('',      url(r'^(?P<quiz_id>\d+)', 'quiz.views.get_form_list'),  )

#models.py
class Choice(models.Model):      choice = models.CharField(max_length=64)      def __unicode__(self):          return self.choice  	  #create a multiple choice quiz to start  class Question(models.Model):      question = models.CharField(max_length=64)      answer = models.CharField(max_length=64)      choices = models.ManyToManyField(Choice)      module = models.CharField(max_length=64)        def __unicode__(self):          return self.question    class Quiz(models.Model):      name = models.CharField(max_length=64)      questions = models.ManyToManyField(Question)        def __unicode__(self):          return self.name

Full Traceback: http://bpaste.net/show/0YNrLYJSdjdJ7Hea5q1c/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Django 1.5 with uwsgi(threaded)/mysql seems to magically cache querysets

So I have some stats reports that I run that it almost seems as if each thread has its own queryset cached.  Each time I refresh they change.  I'm going to revert back to 1.4 due to this bug.  I wish I could come up with a simple example, to demonstrate this, the problem is that the underlying database needs to change between the time each thread serves a request. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: (1242, 'Subquery returns more than 1 row')

On Mon, Apr 1, 2013 at 12:48 PM, Siddharth Ghumre
<siddharth.ghumre92@gmail.com> wrote:
> Hi
>
> As per my view your client query is returning more than one rows from your
> database.
> Suppose your job = 1 which you are getting from your Report table and the
> query ( Job.objects.all().filter(
> client=job)......)fetches two or more than two records from your 'job'
> table.
>
> Now there can be two scenarios:-
> 1.You are looking for a single record to be displayed after executing
> (Job.objects.all().filter(client=job)......)
> In this case you need to use filter query like
> Job.objects.all().filter(Q(client=job)&Q(something=something)&Q(something=something)...)
> which will give you a unique row as per your filter criteria.
>
> 2.You are looking for multiple records to be displayed:-
> In this case you need to add a for after your query.
> Like
> table1=[]
> client = Job.objects.all().filter(client=job)
> for i in client:
> client__client__first_name = i.first_name
> client__client__middle_name = i.middle_name
> ...
> ...
> ...
>
> table1.append({"client__client__first_name":client__client__first_name,"
> client__client__middle_name": client__client__middle_name,.........})
>
>
> temp = {'client':table1, 'cubee':cubee, 'Head':Head,
> 'organisation':organisation,'department':department,}
>
>
> I hope this might solve your problem.


Thanks Siddharth, for the explanation.
>
>
>
>
>
> On Mon, Apr 1, 2013 at 2:51 AM, Satinderpal Singh
> <satinder.goraya91@gmail.com> wrote:
>>
>> I have the following error in my project
>>
>> (1242, 'Subquery returns more than 1 row')
>>
>> my views are as given below
>>
>> def result_cube(request):
>> Id = Cube.objects.aggregate(Max('Report_id'))
>> ID = Id['Report_id__max']
>> cubee = Cube.objects.filter(Report_id = ID)
>> Id = Report.objects.aggregate(Max('id'))
>> ID = Id['id__max']
>> Head = Report.objects.filter(id = ID)
>> organisation = Organisation.objects.all().filter(id = 1)
>> department = Department.objects.all().filter(id = 1)
>>
>> Id = Report.objects.aggregate(Max('job'))
>> ID = Id['job__max']
>> job = Report.objects.filter(job = ID)
>>
>> client =
>> Job.objects.all().filter(client=job).values('client__client__first_name',
>> 'client__client__middle_name', 'client__client__last_name',
>> 'client__client__address', 'client__client__city', 'date',
>> 'letter_no', 'letter_date')
>>
>> temp = {'client':client, 'cubee':cubee, 'Head':Head,
>> 'organisation':organisation,'department':department,}
>> return render_to_response('report/cube.html',
>> dict(temp.items() + tmp.items()),
>> context_instance=RequestContext(request))
>>
>>
>> Error during template rendering
>>
>> In template /home/satinder/Automation/templates/report/header.html,
>> error at line 12
>>
>> 2 {% load i18n %}
>> 3 <html>
>> 4 {% block content %}
>> 5 <body>
>> 6 {% for Heads in Head %}
>> 7 <table width="100%"><tr>
>> 8 <td align="left"><a>No.GNDEC/TCC/R/{{Heads.job_id}}</td><td
>> align="right"><a>Dated{{Heads.dispatch_report_date}}</a></td>
>> 9 </tr></table>
>> 10 <!-- <p><b>Job no:</b><a style="padding-left:30px;
>> position:absolute">{{Heads.job_no}}</a></p>
>> 11 --> <p>To,</p>
>> 12 {% for add in client %}
>> 13 <p> {{ add.client__client__first_name}} {{
>> add.client__client__middle_name}}
>> {{add.client__client__last_name}}</p>
>> 14 <p> {{add.client__client__address}}</p>
>> 15 <p>{{ add.client__client__city}}</p>
>> 16 {% endfor %}
>> 17
>>
>> Can anybody help me to solve this error.
>>
>>
>> --
>> Satinderpal Singh
>> http://devplace.in/~satinder/wordpress/
>> http://satindergoraya.blogspot.in/
>> http://satindergoraya91.blogspot.in/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Satinderpal Singh
http://devplace.in/~satinder/wordpress/
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: error with new version of django.

Ok i got it new version problem........
I ran commond this..
find . -type f -print0 | xargs -0 sed -i 's/ url \([^" >][^ >]*\)/ url "\1"/g'
  It'll go through all of your template files and replace this:
{% url index.html %}

with this

{% url "index.html" %}

Thanks to all


On Mon, Apr 1, 2013 at 1:58 PM, Avnesh Shakya <avnesh.nitk@gmail.com> wrote:
hi,
    I was using django 1.4 version in window 7. now i am using django 1.5 version using virtualenv in ubuntu. now i am running my old project it's generating error.

error is -

NoReverseMatch at /


'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.5.1
Exception Type: NoReverseMatch
Exception Value:
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
Exception Location: /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/defaulttags.py in render, line 402
Python Executable: /home/avin/.virtualenvs/DJ/bin/python
Python Version: 2.7.3
Python Path:
['/home/avin/learnt',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django_socialregistration-0.5.10-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/django_socialregistration-0.5.10-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7',   '/home/avin/.virtualenvs/DJ/lib/python2.7/plat-linux2',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-tk',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-old',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-dynload',   '/usr/lib/python2.7',   '/usr/lib/python2.7/plat-linux2',   '/usr/lib/python2.7/lib-tk',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages']
Server time: Mon, 1 Apr 2013 13:10:52 +0530

Error during template rendering

In template /home/avin/learnt/learnt/templates/homepage/index.html, error at line 44

'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.

34 </div>
35 {% endblock %}
36 {%block navi%}
37 <div class="row">
38 <div class="twelve columns">
39 <nav class="top-bar">
40 <ul>
41 <!-- Title Area -->
42 <li class="name">
43 <h1>
44 <a href="{% url homepage_index %}">
45 Learning Tracker
46 </a>
47 </h1>
48 </li>
49 <li class="toggle-topbar"><a href="#">hhh</a></li>
50 </ul>
51 <ul>
52 <li class="name">
53 <h1>
54 <a class="active" href="{% url homepage_index %}">home</a>

Traceback Switch to copy-and-paste view

  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
    1.                         response = callback(request, *callback_args, **callback_kwargs)
      ...
  • /home/avin/learnt/lrntkr/views.py in index
    1.     return render_to_response('homepage/index.html', ctx,context_instance=RequestContext(request))  
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/shortcuts/__init__.py in render_to_response
    1.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/loader.py in render_to_string
    1.         return t.render(context_instance)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.py in render
    1.             return self._render(context)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.py in _render
    1.         return self.nodelist.render(context)
Please help me how to remove this.....

THANKS,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

error with new version of django.

hi,
    I was using django 1.4 version in window 7. now i am using django 1.5 version using virtualenv in ubuntu. now i am running my old project it's generating error.

error is -

NoReverseMatch at /


'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.5.1
Exception Type: NoReverseMatch
Exception Value:
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
Exception Location: /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/defaulttags.py in render, line 402
Python Executable: /home/avin/.virtualenvs/DJ/bin/python
Python Version: 2.7.3
Python Path:
['/home/avin/learnt',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django_socialregistration-0.5.10-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/django_socialregistration-0.5.10-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',   '/home/avin/.virtualenvs/DJ/lib/python2.7',   '/home/avin/.virtualenvs/DJ/lib/python2.7/plat-linux2',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-tk',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-old',   '/home/avin/.virtualenvs/DJ/lib/python2.7/lib-dynload',   '/usr/lib/python2.7',   '/usr/lib/python2.7/plat-linux2',   '/usr/lib/python2.7/lib-tk',   '/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages',   '/home/avin/.virtualenvs/DJ/lib/python2.7/site-packages']
Server time: Mon, 1 Apr 2013 13:10:52 +0530

Error during template rendering

In template /home/avin/learnt/learnt/templates/homepage/index.html, error at line 44

'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.

34 </div>
35 {% endblock %}
36 {%block navi%}
37 <div class="row">
38 <div class="twelve columns">
39 <nav class="top-bar">
40 <ul>
41 <!-- Title Area -->
42 <li class="name">
43 <h1>
44 <a href="{% url homepage_index %}">
45 Learning Tracker
46 </a>
47 </h1>
48 </li>
49 <li class="toggle-topbar"><a href="#">hhh</a></li>
50 </ul>
51 <ul>
52 <li class="name">
53 <h1>
54 <a class="active" href="{% url homepage_index %}">home</a>

Traceback Switch to copy-and-paste view

  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
    1.                         response = callback(request, *callback_args, **callback_kwargs)
      ...
  • /home/avin/learnt/lrntkr/views.py in index
    1.     return render_to_response('homepage/index.html', ctx,context_instance=RequestContext(request))  
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/shortcuts/__init__.py in render_to_response
    1.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/loader.py in render_to_string
    1.         return t.render(context_instance)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.py in render
    1.             return self._render(context)
      ...
  • /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.py in _render
    1.         return self.nodelist.render(context)
Please help me how to remove this.....

THANKS,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: (1242, 'Subquery returns more than 1 row')

Hi

As per my view your client query is returning more than one rows from your database.
Suppose your job = 1 which you are getting from your Report table and the query ( Job.objects.all().filter(
client=job)......)fetches two or more than two records from your 'job' table.

Now there can be two scenarios:-
1.You are looking for a single record to be displayed after executing  (Job.objects.all().filter(client=job)......)
In this case you need to use filter query like Job.objects.all().filter(Q(client=job)&Q(something=something)&Q(something=something)...) which will give you a unique row as per your filter criteria.

2.You are looking for multiple records to be displayed:-
In this case you need to add a for after your query.
Like
 table1=[]
 client = Job.objects.all().filter(client=job)
 for i in client:
    client__client__first_name = i.first_name
    client__client__middle_name = i.middle_name
    ...
    ...
    ...
   
    table1.append({"client__client__first_name":client__client__first_name," client__client__middle_name": client__client__middle_name,.........})


 temp = {'client':table1, 'cubee':cubee, 'Head':Head, 'organisation':organisation,'department':department,}


I hope this might solve your problem.

-Siddharth





On Mon, Apr 1, 2013 at 2:51 AM, Satinderpal Singh <satinder.goraya91@gmail.com> wrote:
I have the following error in my project

(1242, 'Subquery returns more than 1 row')

my views are as given below

def result_cube(request):
        Id = Cube.objects.aggregate(Max('Report_id'))
        ID = Id['Report_id__max']
        cubee = Cube.objects.filter(Report_id = ID)
        Id = Report.objects.aggregate(Max('id'))
        ID = Id['id__max']
        Head = Report.objects.filter(id = ID)
        organisation = Organisation.objects.all().filter(id = 1)
        department = Department.objects.all().filter(id = 1)

        Id = Report.objects.aggregate(Max('job'))
        ID = Id['job__max']
        job = Report.objects.filter(job = ID)

        client =
Job.objects.all().filter(client=job).values('client__client__first_name',
        'client__client__middle_name', 'client__client__last_name',
        'client__client__address', 'client__client__city', 'date',
'letter_no', 'letter_date')

        temp = {'client':client, 'cubee':cubee, 'Head':Head,
'organisation':organisation,'department':department,}
        return render_to_response('report/cube.html',
dict(temp.items() + tmp.items()),
        context_instance=RequestContext(request))


Error during template rendering

In template /home/satinder/Automation/templates/report/header.html,
error at line 12

2 {% load i18n %}
3 <html>
4 {% block content %}
5 <body>
6 {% for Heads in Head %}
7 <table width="100%"><tr>
8 <td align="left"><a>No.GNDEC/TCC/R/{{Heads.job_id}}</td><td
align="right"><a>Dated{{Heads.dispatch_report_date}}</a></td>
9 </tr></table>
10 <!-- <p><b>Job no:</b><a style="padding-left:30px;
position:absolute">{{Heads.job_no}}</a></p>
11 --> <p>To,</p>
12 {% for add in client %}
13 <p> {{ add.client__client__first_name}} {{
add.client__client__middle_name}}
{{add.client__client__last_name}}</p>
14 <p> {{add.client__client__address}}</p>
15 <p>{{ add.client__client__city}}</p>
16 {% endfor %}
17

Can anybody help me to solve this error.


--
Satinderpal Singh
http://devplace.in/~satinder/wordpress/
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.