Re: django+virtualenv+git(hub)

2013-04-01 Thread +Emmanuel
Here's a link to a setup I found useful and have been using since then:
http://www.jeffknupp.com/blog/2012/10/24/starting-a-django-14-project-the-right-way/

On Saturday, March 30, 2013 10:56:37 AM UTC+3, Martin wrote:
>
> Hi list, 
>
> I'm a Django newbie and have been reading of usefulness of using it with 
> virtualenv+git. I'm not clear however how to set it up in terms of 
> structure/hierarchy. 
>
> Say I've got my ~/projects/django-projects where I want to create my 
> projects so I'd initialise git inside ~/projects/django-projects. Then 
> I'd create separate virtual environments inside that adjusting 
> .gitignore to ignore things like: 
>
> *.pyc 
> .*swp 
>
> # Django files 
> include 
> lib 
> local 
> man 
> share 
> Scripts 
> .Python 
> *.pyc 
> *~ 
> *.db 
>
>
> # Packages 
> *.egg 
> *.egg-info 
> dist 
> build 
> eggs 
> parts 
> bin 
> var 
> sdist 
> develop-eggs 
> .installed.cfg 
>   
> # Installer logs 
>  pip-log.txt 
>
>
>
> Is that a recommended setup/logic? 
>
> Thank you 
>
> John 
>

-- 
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+unsubscr...@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: url tag: "'str' object has no attribute 'regex'"

2013-04-01 Thread Wenliang Chen
Hi,

I got the same issue.  And I solved it doing this:

urlpatterns= patterns('',
(r'^login/$', 'django.contrib.auth.views.login'),   <-Remove the 
last comma in the patterns()
)

Hope this helps

On Friday, May 18, 2012 5:58:28 AM UTC+8, refreegrata wrote:
>
> Hello list
>
> I know, this question has been posted and resolved before, but the 
> solutions don't work in my situation. I don't know why.
>
> When I try to use the "url" tag in any template an exception is raised:
> "'str' object has no attribute 'regex'"
>
> for example, with this I got the error:
> 
> urls.py (main)
> -
> from django.conf.urls import patterns, include, url
>
> urlpatterns= patterns('',
> (r'^registration/', include('apps.registration.urls')),
> (r'', 'django.contrib.auth.views.login'),
> )
> -
>
> urls.py (registration)
> -
> from django.conf.urls import patterns, include, url
>
> urlpatterns= patterns('',
> (r'^login/$', 'django.contrib.auth.views.login'),
> )
> -
>
> login.html (in templates/registration)
> -
> {{ form }}
> {% url "django.contrib.auth.views.login" %} <---here is the problem. It's 
> just an stupid test for the problem
> -
>
> Fail with:
>  - {% url django.contrib.auth.views.login %}
>  - {% url 'django.contrib.auth.views.login' %}
>  - {% url "django.contrib.auth.views.login" %}
>
> I add this at the end of the file "settings.py":
> --
> import django.template
> django.template.add_to_builtins('django.templatetags.future')
> --
> Including or excluding the last lines doesn't matter. The problem appear 
> in the both cases.
>
> I'm using Django 1.4, and Python 2.6 over Centos 6.2. Maybe I must to 
> include something else in the settings?
>
> Thanks for read and sorry for my bad english.
>
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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+unsubscr...@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: Using Django docs to find widget readonly specification

2013-04-01 Thread Daniel Roseman
On Sunday, 31 March 2013 22:42:12 UTC+1, AJP wrote:

> I'm new to learning Django.  I want to find the documentation regarding 
> the readonly attribute you can set for admin widgets.  For example, from an 
> admin.py:
>
> class SourceForm(forms.ModelForm):
>   data = forms.CharField(widget=TextInput(attrs={'readonly': True, 
> 'class': 'averageField'}))
>
>   class Meta:
> model = Source
>
>
> class SourceAdmin(admin.ModelAdmin):
>   form = SourceForm
>
> admin.site.register(Source, SourceAdmin)
>
>
> I've search for readonly on 
> https://docs.djangoproject.com/search/?q=readonly=7 but did not 
> found anything.  Also searching manually in 
> https://docs.djangoproject.com/en/dev/ref/forms/widgets/ didn't bring 
> anything up.  Can someone tell me where I'm going wrong please.
>

This is not documented on the Django site because it has nothing to do with 
Django. As the docs do explain, the `attrs` are used to set any HTML 
attributes on the rendered widget. `readonly` is an attribute belonging to 
the HTML input and select elements.
--
DR.

-- 
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+unsubscr...@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: djano user registration form and login(full example)

2013-04-01 Thread Alexis Roda

Al 01/04/13 21:11, En/na sachin ha escrit:

Hello,

I'm just starting with Django. I want to create a user registration form
which will take input like username, password, first and last name,
email, address etc.
using the same information I want to send a conformation mail to user
and authenticate her/him.


Hi sachin,
I'd suggest you to take a look at django-registration. It does what 
you're asking for.


https://bitbucket.org/ubernostrum/django-registration
http://docs.b-list.org/django-registration/0.8/


HTH

--
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+unsubscr...@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: djano user registration form and login(full example)

2013-04-01 Thread Shawn Milochik
Don't even worry about factories. They're for when you want a bunch of
forms for the same model on the page at once.

Use the UserCreationForm in django.contrib.auth.forms. It only accepts
a username and password, so you can either subclass it to add the
fields or make your own form and add it to your view so that they both
appear in the same HTML form. You can validate both and do what you
need to do.

You definitely shouldn't be writing validation logic for the password
and username and such -- that's what ModelForms are for.

If you have more specific questions just ask.

-- 
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+unsubscr...@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.




djano user registration form and login(full example)

2013-04-01 Thread sachin
Hello,

I'm just starting with Django. I want to create a user registration form 
which will take input like username, password, first and last name, email, 
address etc.
using the same information I want to send a conformation mail to user and 
authenticate her/him.

I have read Django docs, from what I read either I can create a model and 
form separately and write authentication and other logic on my own. Other 
way is
to user 'formset_factory' to directly create form from model. In second 
case how m I going to handle password(hashing) and authentication of user?

Can Django's *auth module can be used? If yes how ?

It will be great if any one redirect me to appropriate complete example, at 
least to start with.

Thanx.

-- 
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+unsubscr...@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: Hey! I'm recieving an index error when trying to import models, and I can't figure out why.

2013-04-01 Thread Bill Freeman
Stick a print statement between lines 91 and 92 to show you
model_module.__name__ .
(or use pdb if you're comfortable with it).  My best guess is that the
split() is returning a
list of one item.  That is, that there is no '.' in model_module.__name__
.  Thus an index
of -2 failss: there is no penultimate item.

At least for the time when it gets the exception.  That is, you may get
many lines printed,
but the last one before the exception won't have a '.'


On Mon, Apr 1, 2013 at 1:48 PM, C Alaric Moore wrote:

> I just tried this and still have the same error. I also might add that I'm
> using a mac with an updated os. I also hear that it could be an issue of
> line breaks, but can't find any /n's or /r's in any of the code anyway. I
> might just be looking in the wrong places, too.
>
>
> On Sunday, March 31, 2013 9:33:21 PM UTC-7, jondbaker wrote:
>
>> When importing Python modules, you don't need to include the '.py' file
>> extension. So,
>> from models.py import UUID
>> ...needs to be:
>> from models import UUID
>>
>> Hope this helps,
>> Jonathan
>>
>>
>> On Sun, Mar 31, 2013 at 10:27 PM, C Alaric Moore wrote:
>>
>>> Hello,
>>>
>>> I am incredibly new to Django, as-of-today new, so forgive me if I've
>>> missed something really obvious.
>>>
>>> I've been going through the tutorial and did so mostly-successfully and
>>> decided to redo it with my own code.
>>>
>>> Everything was going fine until I decided that it would be a good idea
>>> to type from models.py import UUID, Students into the shell. With this I
>>> received the following error:
>>>
>>> /Library/Frameworks/Python.**framework/Versions/7.3/lib/**
>>> python2.7/site-packages/**django/db/models/base.pyc in __new__(cls,
>>> name, bases, attrs)
>>>  90 # For 'django.contrib.sites.models', this would be
>>> 'sites'.
>>>
>>>  91 model_module = sys.modules[new_class.__**module__]
>>> ---> 92 kwargs = {"app_label": model_module.__name__.split('.
>>> **')[-2]}
>>>  93 else:
>>>  94 kwargs = {}
>>>
>>> IndexError: list index out of range
>>>
>>> I went onto stackoverflow and found some people had similar issues a
>>> year ago, and suggested that a person delete the pyc files, which I did. It
>>> was also suggested that you make DEBUGGING = False, or True or whatever is
>>> opposite. I did this, too, only to find the same error.
>>>
>>> I did some other things too, all to no avail... all the same error. I
>>> even checked to make sure I was saving edited files, TWICE. Still, same
>>> error.
>>>
>>> With this, I ask for your help o' wise ones.
>>>
>>> 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...@**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
>>> .
>>>
>>>
>>>
>>
>>
>>
>> --
>> Jonathan D. Baker
>> Developer
>> http://jonathandbaker.com
>>
>  --
> 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+unsubscr...@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+unsubscr...@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: Hey! I'm recieving an index error when trying to import models, and I can't figure out why.

2013-04-01 Thread C Alaric Moore
I just tried this and still have the same error. I also might add that I'm 
using a mac with an updated os. I also hear that it could be an issue of 
line breaks, but can't find any /n's or /r's in any of the code anyway. I 
might just be looking in the wrong places, too. 

On Sunday, March 31, 2013 9:33:21 PM UTC-7, jondbaker wrote:
>
> When importing Python modules, you don't need to include the '.py' file 
> extension. So,
> from models.py import UUID
> ...needs to be:
> from models import UUID
>
> Hope this helps,
> Jonathan
>
>
> On Sun, Mar 31, 2013 at 10:27 PM, C Alaric Moore 
>  > wrote:
>
>> Hello, 
>>
>> I am incredibly new to Django, as-of-today new, so forgive me if I've 
>> missed something really obvious. 
>>
>> I've been going through the tutorial and did so mostly-successfully and 
>> decided to redo it with my own code. 
>>
>> Everything was going fine until I decided that it would be a good idea to 
>> type from models.py import UUID, Students into the shell. With this I 
>> received the following error: 
>>
>> /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/db/models/base.pyc
>>  
>> in __new__(cls, name, bases, attrs)
>>  90 # For 'django.contrib.sites.models', this would be 
>> 'sites'.
>>
>>  91 model_module = sys.modules[new_class.__module__]
>> ---> 92 kwargs = {"app_label": 
>> model_module.__name__.split('.')[-2]}
>>  93 else:
>>  94 kwargs = {}
>>
>> IndexError: list index out of range
>>
>> I went onto stackoverflow and found some people had similar issues a year 
>> ago, and suggested that a person delete the pyc files, which I did. It was 
>> also suggested that you make DEBUGGING = False, or True or whatever is 
>> opposite. I did this, too, only to find the same error. 
>>
>> I did some other things too, all to no avail... all the same error. I 
>> even checked to make sure I was saving edited files, TWICE. Still, same 
>> error. 
>>
>> With this, I ask for your help o' wise ones. 
>>
>> 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...@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.
>>  
>>  
>>
>
>
>
> -- 
> Jonathan D. Baker
> Developer
> http://jonathandbaker.com
>  

-- 
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+unsubscr...@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: Confusion about Static Files

2013-04-01 Thread yakoub abaya
it is very simple and doesn't require a separate http server like nginx 
first you configure in settings.py the variables STATIC_ROOT and 
STATIC_URL, then configure http server accordingly 
STATIC_ROOT is the absolute path in filesystem that stores your static 
files, you can put that inside django project itself if it is convenient 
and then in apache use Alias and Directory accordingly

STATIC_ROOT = '/srv/django/static_files'
STATIC_URL = '/django_static/'
then in apache :
ALias /django_static/ /srv/django/static_files/

  Require all granted


On Friday, March 29, 2013 10:36:30 PM UTC+3, David Pitchford 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+unsubscr...@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.




template composition

2013-04-01 Thread yakoub abaya
i read about template inheritance and think it is great
but there is the possibility of including one template output as context 
variable for another template
for example :
*
c = new RequestContest()
c['navigation'] = render_to_string('navigation.html', {'links': links})

output = render_to_response('page.html', {}, c)

*and then in page.html :
*

 {{ navigation }} 
 ... 



*so my question is would this method break cache or damage performance or 
some other problem ?

-- 
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+unsubscr...@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: Django 1.5 with uwsgi(threaded)/mysql seems to magically cache querysets

2013-04-01 Thread budlight
So far I don't have this issue at all with 1.4,  which makes sense as it 
started exactly at the 1.5 upgrade time for me.

On Monday, April 1, 2013 7:40:08 AM UTC-6, budl...@gmail.com wrote:
>
> 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+unsubscr...@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: Confusion about Static Files

2013-04-01 Thread David Pitchford
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).
> https://github.com/nimbis/mezzanine-project/blob/master/deploy/
> 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
> bfsc...@gmail.com 
>
>
>  
> On Mar 29, 2013, at 3:36 PM, David Pitchford 
>  
> 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 
> 

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

2013-04-01 Thread Cody Scott
I am trying to make a simple quiz app.

I am trying to go to the URL /quiz/ 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\d+)', QuizWizard.as_view(get_form_list)),
the function get_form_list has no length

(r'^(?P\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.pyclass 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\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+unsubscr...@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

2013-04-01 Thread budlight
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+unsubscr...@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')

2013-04-01 Thread Satinderpal Singh
On Mon, Apr 1, 2013 at 12:48 PM, Siddharth Ghumre
 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)(something=something)(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
>  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 
>> 4 {% block content %}
>> 5 
>> 6 {% for Heads in Head %}
>> 7 
>> 8 No.GNDEC/TCC/R/{{Heads.job_id}}> align="right">Dated{{Heads.dispatch_report_date}}
>> 9 
>> 10  To,
>> 12 {% for add in client %}
>> 13  {{ add.client__client__first_name}} {{
>> add.client__client__middle_name}}
>> {{add.client__client__last_name}}
>> 14  {{add.client__client__address}}
>> 15 {{ add.client__client__city}}
>> 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+unsubscr...@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+unsubscr...@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+unsubscr...@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, 

Re: error with new version of django.

2013-04-01 Thread Avnesh Shakya
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  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  35 {% endblock %} 36 {%block navi%} 37  class="row"> 38  39  40 
> 41  42  43  44  45 Learning Tracker 46  47  48  49  class="toggle-topbar">hhh 50  51  52  class="name"> 53  54 home
> Traceback Switch to copy-and-paste view 
>
>-
>
> /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/core/handlers/base.pyin
>get_response
>1.
>
>   response = callback(request, *callback_args, 
> **callback_kwargs)
>
>   ...
> ▶ Local vars 
>- /home/avin/learnt/lrntkr/views.py in index
>1.
>
>   return render_to_response('homepage/index.html', 
> ctx,context_instance=RequestContext(request))
>
>   ...
> ▶ Local vars 
>-
>
> /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/shortcuts/__init__.pyin
>render_to_response
>1.
>
>   return HttpResponse(loader.render_to_string(*args, **kwargs), 
> **httpresponse_kwargs)
>
>   ...
> ▶ Local vars 
>-
>
> /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/loader.pyin
>render_to_string
>1.
>
>   return t.render(context_instance)
>
>   ...
> ▶ Local vars 
>-
>
> /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.pyin
>render
>1.
>
>   return self._render(context)
>
>   ...
> ▶ Local vars 
>-
>
> /home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.pyin
>_render
>1.
>
>   return self.nodelist.render(context)
>
>
> 

error with new version of django.

2013-04-01 Thread Avnesh Shakya
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  35 {% endblock %} 36 {%block navi%} 37  38  39  40  
41  42  43  44  45 Learning Tracker 46  47  48  49 hhh 50  51  52  53  54 home  
Traceback Switch to copy-and-paste view  
   
   - 
   
/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/core/handlers/base.pyin
 
   get_response 
   1. 
  
  response = callback(request, *callback_args, 
**callback_kwargs)
  
  ...
▶ Local vars  
   - /home/avin/learnt/lrntkr/views.py in index 
   1. 
  
  return render_to_response('homepage/index.html', 
ctx,context_instance=RequestContext(request))
  
  ...
▶ Local vars  
   - 
   
/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/shortcuts/__init__.pyin
 
   render_to_response 
   1. 
  
  return HttpResponse(loader.render_to_string(*args, **kwargs), 
**httpresponse_kwargs)
  
  ...
▶ Local vars  
   - 
   
/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/loader.pyin
 
   render_to_string 
   1. 
  
  return t.render(context_instance)
  
  ...
▶ Local vars  
   - 
   
/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.pyin
 
   render 
   1. 
  
  return self._render(context)
  
  ...
▶ Local vars  
   - 
   
/home/avin/.virtualenvs/DJ/local/lib/python2.7/site-packages/django/template/base.pyin
 
   _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+unsubscr...@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')

2013-04-01 Thread Siddharth Ghumre
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)(something=something)(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.goray...@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 
> 4 {% block content %}
> 5 
> 6 {% for Heads in Head %}
> 7 
> 8 No.GNDEC/TCC/R/{{Heads.job_id}} align="right">Dated{{Heads.dispatch_report_date}}
> 9 
> 10  To,
> 12 {% for add in client %}
> 13  {{ add.client__client__first_name}} {{
> add.client__client__middle_name}}
> {{add.client__client__last_name}}
> 14  {{add.client__client__address}}
> 15 {{ add.client__client__city}}
> 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+unsubscr...@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+unsubscr...@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: Data Structure - Orders and multiple items

2013-04-01 Thread Siddharth Ghumre
Sorry for the half response...please ignore the previous message.

class order(models.Model):
order_id = models.IntegerField(unique=True)
customer_id = models.ForeignKey('Customer')
item_id = models.ForeignKey('Item')
qty = models.IntegerField()

This will you give the provision to store multiple items to be added
against each customer and the quantity of the order against each customer.

-Siddharth



On Mon, Apr 1, 2013 at 9:37 AM, Eric Lovrien  wrote:

> I am not sure of how or the best way to structure my data in models.py. I
> would like to have an order and allow multiple items / products to be added
> to an order. I know I can do a ManyToMany field but not sure how I would
> connect a qty to that. I am sure there is some simple way of doing this, or
> a better way to model the data. I know in many ERP systems they have an
> orders table and then an orders details table. Below is just a quick
> mock-up of how i was thinking on to do it until I started thinking about
> the many items and qty to an single order issue came up. Can any one give
> me some tips on how to accomplish this?
>
>
>
> class Item(models.Model):
> name = models.CharField(max_length200)
> description = models.TextField(blank=True)
>
> def __unicode__(self):
>  return self.name
>
> class Customer
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> address = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.name
>
> class order(models.Model):
> order = models.IntegerField(unique=True)
> customer = models.ForeignKey('Customer')
>
> --
> 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+unsubscr...@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+unsubscr...@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: Data Structure - Orders and multiple items

2013-04-01 Thread Siddharth Ghumre
Hi

As per my view you can modify your models as follows:-

class order(models.Model):
order_id = models.IntegerField(unique=True)
customer_id = models.ForeignKey('Customer')
item_id = models.ForeignKey('Item')




On Mon, Apr 1, 2013 at 10:30 AM, Lachlan Musicman  wrote:

> On 1 April 2013 15:07, Eric Lovrien  wrote:
> > I am not sure of how or the best way to structure my data in models.py. I
> > would like to have an order and allow multiple items / products to be
> added
> > to an order. I know I can do a ManyToMany field but not sure how I would
> > connect a qty to that. I am sure there is some simple way of doing this,
> or
> > a better way to model the data. I know in many ERP systems they have an
> > orders table and then an orders details table. Below is just a quick
> mock-up
> > of how i was thinking on to do it until I started thinking about the many
> > items and qty to an single order issue came up. Can any one give me some
> > tips on how to accomplish this?
>
>
> Use an intermediary model as described in the docs:
>
>
> https://docs.djangoproject.com/en/1.5/topics/db/models/#extra-fields-on-many-to-many-relationships
>
> This will be your best bet I think.
>
> L.
>
>
>
> >
> >
> >
> > class Item(models.Model):
> > name = models.CharField(max_length200)
> > description = models.TextField(blank=True)
> >
> > def __unicode__(self):
> >  return self.name
> >
> > class Customer
> > first_name = models.CharField(max_length=100)
> > last_name = models.CharField(max_length=100)
> > address = models.CharField(max_length=200)
> >
> > def __unicode__(self):
> > return self.name
> >
> > class order(models.Model):
> > order = models.IntegerField(unique=True)
> > customer = models.ForeignKey('Customer')
> >
> > --
> > 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+unsubscr...@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.
> >
> >
>
>
>
> --
> The new creativity is pointing, not making. Likewise, in the future,
> the best writers will be the best information managers.
>
>
> http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith
>
> --
> 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+unsubscr...@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+unsubscr...@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.