How to assign form names in formset before rendering??

2011-02-20 Thread balu
Hi all...

I'm working on building an oline examination system. Here is a view
which picks some questions randomly from the database and generates 10
questions.

I could able to display these questions on the web page. In that web
page there should be a formset which have options A, B, C, D. The name
of the form in that "formset" should be the unique question ID which I
gave.

How to assign form ID to each form in a "frameset" Before it renders
to the user??

Please give me your suggestions. I don't have any Idea on this.

Here is the view which calculates the random questions.

//*views.py***//

from django.forms.formsets import formset_factory


def start_exam(request, sub_code, template_name = 'accounts/
start_exam.html', answer_form=AnswerForm, current_app=None,
extra_context=None):

nq_in_exam = 10

if request.method == "POST":
//some logic goes here to process the submitted form.
else:
questions = Question.objects.filter(subject_code = sub_code)

n = questions.count()
if (n < nq_in_exam):
return render_to_response(template_name)

m = int(math.floor(n/nq_in_exam))

position = 0
temp_list=[]
id_list = []

for object in Question.objects.filter(subject_code = sub_code):
temp_list.append(object.id)

for i in range(nq_in_exam):
id_list.append(temp_list[int(position
+math.floor(random.random()*m))])
position +=m

exam = Question.objects.filter(id__in = id_list)

formset = formset_factory(answer_form)

context = { 'formset': formset, 'questions':exam }

context.update(extra_context or {})

return render_to_response(template_name, context,
context_instance=RequestContext(request, current_app=current_app))


--
Here is the form which is to be in formset.

//*forms.py*//

ANSWER_CHOICES = (('A','A'),('B','B'),('C','C'),('D','D'))

class AnswerForm(forms.Form):
options = forms.ChoiceField(choices = ANSWER_CHOICES, widget =
forms.RadioSelect())

---
Here is the template logic I have written to render that page.


{%for form in formset%}
{{form}}
{%endfor%}







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



Re: testing foo_set existence for each object in a queryset

2011-02-20 Thread Dan
Thanks Shawn

That's helpful.  I was actually looking at the manager documentation
today thinking perhaps that was what I needed - but couldn't quite
wrap my head around it.  But knowing that it indeed is the way to go
will no doubt provide the motivation I need.

(I have problems learning anything if I'm not sure it solves a problem
I have).

On Feb 20, 4:12 pm, Shawn Milochik  wrote:
> Not only is it not a stupid question, but it's one of the best
> possible types of questions. Any time someone comes in and makes it
> obvious that they've thought about their problem and made an attempt
> to solve it themselves, they get my respect.
>
> The easiest answer to your question is to make a custom manager (a
> subclass of models.Manager) for your model.
>
> http://docs.djangoproject.com/en/1.2/topics/db/managers/
>
> You can add your logic to an override of the get() of filter(), or add
> an entirely new method, such as pending() or ready_to_send().
>
> If your data grows to the point where this becomes unwieldy, you could
> speed things up by using signals, so that instances of the model
> represented by 'foo' in your example would update a field in your main
> model when they are created, changed, or deleted. This would allow you
> to use metadata in your main model instead of having to do the extra
> joins on every database read.
>
> Shawn

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



Re: testing foo_set existence for each object in a queryset

2011-02-20 Thread Dan
Hi Lior,

Thanks for the effort - but I'm not sure it can be done this way.  The
problem is the related model is not accessible at the level of MyModel
- only at the level of its instances (if I'm saying that correctly).

So if I try something like that I get the error message:

"Cannot resolve keyword 'foo_set' into field.  Choices are:  ..."

You did give me an idea though...

MyModel.objects.filter(foo__endtime__gt =
datetime.datetime.now()).distinct()

This seems to work.  Dammit - there goes my motivation to learn about
managers.  :)

Actually - that's the same as "SELECT DISTINCT" in sql - so is perhaps
not very efficient...  That should provide a bit of a motivation boost
at least.

Thanks for the help.




On Feb 20, 5:00 pm, Lior Sion  wrote:
> Dan,
>
> If I understand your question correctly, you are struggling with
> creating the filtering you wrote in your message on the queryset level
> (without going to the db for each object), right?
>
> Hard to say without actually seeing your code and testing, but would
> this be the same?
>
> MyModel.objects.filter(foo_set__endtime__gt ==
> datetime.datetime.now())
>
> I don't think you'll need the exists, as only existing objects will
> come back from the query.
>
> On Feb 20, 3:50 am, Dan  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > Long time lurker - first time poster - hopefully future answerer...
>
> > Basically what I want to do can be done with:
>
> > result = [w for w in MyModel.objects.all() if
> > w.foo_set.filter(endtime__gt = datetime.datetime.now()).exists()]
>
> > Is there anyway to do this using the queryset api?
>
> > Hopefully it's not too stupid a question...

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



Not able to use ModelForm

2011-02-20 Thread The_Legend
i am not able to use model forms to input data for models in database.

model.py --

gender_list = (('M', 'Male'), ('F', 'Female' ))
class people(models.Model):
userID = models.ForeignKey(User, unique=True)
name = models.CharField('name',max_length=30)
address = models.CharField('address',max_length=50)
enrol_no = models.IntegerField('enrol',max_length=10);
email = models.EmailField()
date_of_birth = models.DateField('birthday')
gender = models.CharField(max_length=1, choices=gender_list)

view.py --

class popform(ModelForm):
class Meta:
model = people

def create_user(request):
message = 'Create New User'
uForm = NewUserForm()
if request.method == 'POST':
if request.POST['submit'] == 'Create':
postDict = request.POST.copy()
uForm = NewUserForm(postDict)
try:
#user object
user = User.objects.create_user(postDict['username'],
postDict['email'],
postDict['password'])
user.last_name = postDict['last']
user.first_name = postDict['first']
user.save()

#people object
perDict = {}
perDict['userID'] = user.id
perDict['name'] = postDict['first']
perDict['email'] = postDict['email']
perDict['gender'] = postDict['gender']
perDict['enrol'] = postDict['enrol_no']
dt = people()
form=popform(instance=dt)
if form.is_valid():
   try:
form.save()
return render_to_response('/login/')
   except:
message = 'Database Error.'
user.delete()
else:
message = 'Form Data Error'
user.delete()
except:
message = 'User creation Error'
return render_to_response('register.html',{
'uForm': uForm,
'message': message })

please need help

Thank you.


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



Re: Not able to use ModelForm

2011-02-20 Thread Daniel Roseman
On Sunday, February 20, 2011 11:26:18 AM UTC, The_Legend wrote:
>
> i am not able to use model forms to input data for models in database. 
>
>
I'd get some treatment for that, if I were you.

Seriously, what problem are you having? Are we supposed to guess?
--
DR. 

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



Re: Not able to use ModelForm

2011-02-20 Thread The_Legend
Oh sorry, i thought i wrote, but i guess it didnt convey the message.

have written a registration form. so it takes data from this form then
first creates a user  then i have a model called people in my app
called mainapp. so i just need to add data to the database for this
model. but i am not able to.

in this part if i give it like this ---

dt = people()
tform=popform(instance=dt)
form = tform(perDict)
if form.is_valid():-- it says object not callable --
tform(perDict) where perDict is dictionary

and if i give
dt = people()
form = popform(perDict)
if form.is_valid():--then it always comesout invalid








On Feb 20, 4:34 pm, Daniel Roseman  wrote:
> On Sunday, February 20, 2011 11:26:18 AM UTC, The_Legend wrote:
>
> > i am not able to use model forms to input data for models in database.
>
> I'd get some treatment for that, if I were you.
>
> Seriously, what problem are you having? Are we supposed to guess?
> --
> DR.

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



stop caching json response

2011-02-20 Thread Олег Корсак
Hello. I have memcached mw enabled. And I can see that response is
cached in memcached. I want to stop caching that. How is it possible to
do? Thanks

def do_something(request):
return HttpResponse('yoyoyo23', content_type = 'application/javascript;
charset=utf8')



signature.asc
Description: OpenPGP digital signature


Re: Not able to use ModelForm

2011-02-20 Thread Daniel Roseman
On Sunday, February 20, 2011 12:05:12 PM UTC, The_Legend wrote:
>
> Oh sorry, i thought i wrote, but i guess it didnt convey the message. 
>
> have written a registration form. so it takes data from this form then 
> first creates a user  then i have a model called people in my app 
> called mainapp. so i just need to add data to the database for this 
> model. but i am not able to. 
>
> in this part if i give it like this --- 
>
> dt = people() 
> tform=popform(instance=dt) 
> form = tform(perDict) 
> if form.is_valid():-- it says object not callable -- 
> tform(perDict) where perDict is dictionary 
>
> and if i give 
> dt = people() 
> form = popform(perDict) 
> if form.is_valid():--then it always comesout invalid 


Well, there was no way to tell that from the original posting because it 
didn't include any of that code.

This code is very bizarre. You instantiate the form with 
`tform=popform(instance=dt)` and then attempt to call it again with 
`tform(perDict)`. I expect that the `object not callable` exception actually 
happens here, not in the is_valid() call.

The correct way to instantiate a form from a post using an existing model 
instance is to pass both arguments at the same time:

`tform = popform(perDict, instance=dt)`

Also, you should consider why you need to pre-process the request to get the 
perDict dictionary. It would make more sense to use the same field names in 
the template as in the form.
--
DR.

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



Customize inlines in django admin

2011-02-20 Thread Gianluca Pacchiella
Hi folks,

I have a problem with an admin inline form for a model having a ManyToMany 
field: the default is to
visualize a select having as options all the instances available for that kind 
of model, with a plus button to
create a new one on the fly.

My problem is I want only to add the object created with the popup window and 
not to have the
select with all the other instances and in the change page I only want the 
object instance previously
added and not all the available instances for that kind of model.

Is there any simple way to accomplish this?

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



Application Name in Django urls.

2011-02-20 Thread Uolter
I am running Pootle http://translate.sourceforge.net/wiki/pootle/index
which is basically a Django apps on dabian server. All the urls look
like:
http:///account/login?next=index
http:///docs/index.html
http:///admin/
and so on.

I would like to add the application name before each path:
http:account/login?next=index
http:docs/index.html
etc.

How can I do that without changing the code? Urls inside templates are
always relatives.
Is there any configuration in Django?
I also have an apache in front of it.

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



Re: Not able to use ModelForm

2011-02-20 Thread The_Legend
Daniel thanks man for helping, and noticing problems in that dirty
mess. i am basically very new to django.
I hadn't given a field called address in the form, and + didnt give it
blank=True in the model either so i guess it wasnt working, + what you
said was also true.

thanks a lot, hope u are always there to help ;)

On Feb 20, 7:56 pm, Daniel Roseman  wrote:
> On Sunday, February 20, 2011 12:05:12 PM UTC, The_Legend wrote:
>
> > Oh sorry, i thought i wrote, but i guess it didnt convey the message.
>
> > have written a registration form. so it takes data from this form then
> > first creates a user  then i have a model called people in my app
> > called mainapp. so i just need to add data to the database for this
> > model. but i am not able to.
>
> > in this part if i give it like this ---
>
> > dt = people()
> > tform=popform(instance=dt)
> > form = tform(perDict)
> >     if form.is_valid():    -- it says object not callable --
> > tform(perDict) where perDict is dictionary
>
> > and if i give
> > dt = people()
> > form = popform(perDict)
> >     if form.is_valid():    --then it always comesout invalid
>
> Well, there was no way to tell that from the original posting because it
> didn't include any of that code.
>
> This code is very bizarre. You instantiate the form with
> `tform=popform(instance=dt)` and then attempt to call it again with
> `tform(perDict)`. I expect that the `object not callable` exception actually
> happens here, not in the is_valid() call.
>
> The correct way to instantiate a form from a post using an existing model
> instance is to pass both arguments at the same time:
>
>     `tform = popform(perDict, instance=dt)`
>
> Also, you should consider why you need to pre-process the request to get the
> perDict dictionary. It would make more sense to use the same field names in
> the template as in the form.
> --
> DR.

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



Re: stop caching json response

2011-02-20 Thread Shawn Milochik
A quick and dirty way is to append a timestamp to the URL so it's
always unique. That way it won't be cached.

Add "new Date().getTime()" to the end of the URL your AJAX call
requests. Just have your url pattern accept and ignore the extra
stuff.

Shawn

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



Re: How to pivot a table?

2011-02-20 Thread idahogray
I am not sure what database you are using, but I just did this using a
raw query and postgresql's crosstab function.

http://www.postgresql.org/docs/current/static/tablefunc.html
http://docs.djangoproject.com/en/1.2/topics/db/sql/#executing-custom-sql-directly

On Feb 18, 7:25 am, Derek  wrote:
> On Feb 17, 10:52 pm, Phlip  wrote:
>
>
>
>
>
> > Djangoists:
>
> > I have a database table like this...
>
> >   red, 1
> >   red, 2
> >   red, 15
> >   blue, 18
> >   blue, 20
>
> > ...and I want to read it into an array like this:
>
> >   [ ['red', [1,2,15]], ['blue', [18,20]], ]
>
> > Of course I can use values_list('color', 'number'), and then re-pack
> > the array with a for-loop.
>
> > Do QuerySet aggregations and annotations offer some way to push that
> > query into the database?
>
> Assuming you want an output in array format (as per the first part of
> your 
> question):http://stackoverflow.com/questions/1859031/how-could-create-a-crossta...

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



Re: stop caching json response

2011-02-20 Thread Eric Hutchinson
check out: 
http://docs.djangoproject.com/en/1.2/topics/cache/#controlling-cache-using-other-headers

On Feb 20, 7:06 am, Олег Корсак 
wrote:
> Hello. I have memcached mw enabled. And I can see that response is
> cached in memcached. I want to stop caching that. How is it possible to
> do? Thanks
>
> def do_something(request):
>         return HttpResponse('yoyoyo23', content_type = 
> 'application/javascript;
> charset=utf8')
>
>  signature.asc
> < 1KViewDownload

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



Populating extra fields on models at init that doesn't have to be saved in table and originally isn't part of the model.

2011-02-20 Thread Christan
I've this model

class DistributionList(CommonList):
distributionListID = models.IntegerField()

NB: CommonList is another model with abstract=True in Meta class. (Abstract 
Base Class)

Now, On the initialization of this DistributionList(whether newly created or 
retrieved from db), I've to call a web service with distributionListID as 
parameter and associate the return value (say of class Foo) with the 
instance.

I think post_init signal is the way. Am I right? (or is it overriding 
__init__ )

Does the call to save store instance of Foo, that I set in __init__ or with 
post_init signal in database?

If it does, then,  I don't need the returned instance of Foo to be stored in 
db when save method of distributionList is called.
Else, which is the best way, overriding __init__ or using post_init

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



What will happen when a model I modified get saved.

2011-02-20 Thread Christan
See the model below,

class Foo(models.Model):
x = model.IntegerField()

Also, a class as follows

class Bar(Object):
y = 1212121L

-

Now, If I modified above Foo like this

class Foo(models.Model):
x = model.IntegerField()
y = Bar()

and in the shell, 

from xyz.models import Foo, Bar
a=Foo()
b=Bar()
b.y=56

a.x=1
a.y=b
a.save() # what will happen???

On a.save(), I see no error.
Is it that, the extra field y get silently set away while saving!!!

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



Re: What will happen when a model I modified get saved.

2011-02-20 Thread Shawn Milochik
First, what are you trying to do?

1. The code you posted is not valid Python, because 'Object' is
capitalized. So you haven't actually even tried this, or it would have
blown up.
2. Adding 'y' to your subclass of Model does nothing with the
database, because y is not a subclass of one of the fields the model
class provides.
3. If you've created your database already using syncdb and then
changed the model, your database won't change. You need to use South
or destroy and re-create the database.

Shawn

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



Re: What will happen when a model I modified get saved.

2011-02-20 Thread Christan

1) That was a typo, forget it.
2) This answers my question, Thanks :)
3) I know this, but haven't tried South yet. 

BTW., Thank you for your time

>

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



post_init signal or overriding __init__ which is the way to go

2011-02-20 Thread Christan
By another post I simultaneously posted with this one, 
Now, I confirmed myself that instance of Foo that gets associated with 
 model instance will not be saved in db, because it's not a subclass of one 
of the fields that model provides. 

*Now, only thing remaining is, whether I use post_init signal 
or override __init__ of DistributionList.*

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



Select x random rows from DB

2011-02-20 Thread galago
What is the best way, to select X random rows from DB? I know that 
method: .all().order_by('?')[:X] is not good idea.
What methods do you use?

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



Re: Select x random rows from DB

2011-02-20 Thread galago
If i knew what is a good idea, I wouldn't aks here:D
I only know - that described method is DB killer :)

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



Re: Select x random rows from DB

2011-02-20 Thread delegbede
Knowing what is not a good idea means you know what the good idea is, 
logically. 
So, Galago, what's the good idea???
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: galago 
Sender: django-users@googlegroups.com
Date: Sun, 20 Feb 2011 14:19:14 
To: 
Reply-To: django-users@googlegroups.com
Subject: Select x random rows from DB

What is the best way, to select X random rows from DB? I know that 
method: .all().order_by('?')[:X] is not good idea.
What methods do you use?

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


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



Re: Select x random rows from DB

2011-02-20 Thread Cal Leeming [Simplicity Media Ltd]
Hi Galago,

There are several ways to do this, and it really depends on the size of your
database, and what your storage policies are.

Here are some of the various methods we have used:

   - Use ID max, then random.randint().
   Only works if you *never* delete rows from the database, and instead have
   a field called 'is_deleted', which is set to 1 each time. Great if you have
   a database with more than 100 thousand rows.
   POC: from django.db.models import Max,Count,Q,F; total_items =
   model.aggregate(Max('id'))['id__max']; random.randint(0,total_items)

   - Use .count(), then random.randint()
   Count is slow as hell depending on how many rows you have.

   - Use ORDER BY RAND() inside the SQL itself, although from what I
   remember, this wasn't great.

It really does just come down to how well your database has been designed,
how many rows you have, and what you are attempting to achieve. I would
suggest creating a script which benchmarks all these different methods
against the data you have, and see which comes out top, that's what we do,
the results are sometimes surprising :)

Hope this helps.

Cal


On Sun, Feb 20, 2011 at 10:19 PM, galago  wrote:

> What is the best way, to select X random rows from DB? I know that
> method: .all().order_by('?')[:X] is not good idea.
> What methods do you use?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Select x random rows from DB

2011-02-20 Thread delegbede
That would have been my approach if I were to do that. So, we are now two 
seeking the good way to get it done. 
Hello People,
Galago and I have the same challenge, please help us. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: galago 
Sender: django-users@googlegroups.com
Date: Sun, 20 Feb 2011 14:24:37 
To: 
Reply-To: django-users@googlegroups.com
Subject: Re: Select x random rows from DB

If i knew what is a good idea, I wouldn't aks here:D
I only know - that described method is DB killer :)

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


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



Re: Select x random rows from DB

2011-02-20 Thread Cal Leeming [Simplicity Media Ltd]
Also, this snippet isn't directly related, but it does show the methods we
used to paginate through 50 million rows, with query times of below 0.5
seconds :) It uses the same method that was in my first suggestion (the ID
max thing)

http://djangosnippets.org/snippets/2277/

Cal

On Sun, Feb 20, 2011 at 10:26 PM,  wrote:

> That would have been my approach if I were to do that. So, we are now two
> seeking the good way to get it done.
> Hello People,
> Galago and I have the same challenge, please help us.
>
> Sent from my BlackBerry wireless device from MTN
> --
> *From: * galago 
> *Sender: * django-users@googlegroups.com
> *Date: *Sun, 20 Feb 2011 14:24:37 -0800 (PST)
> *To: *
> *ReplyTo: * django-users@googlegroups.com
> *Subject: *Re: Select x random rows from DB
>
> If i knew what is a good idea, I wouldn't aks here:D
> I only know - that described method is DB killer :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Select x random rows from DB

2011-02-20 Thread Cal Leeming [Simplicity Media Ltd]
Also, take strong notice of this part:

EXAMPLE:>>> _t = time.time(); x = map(lambda x: x,
Post.objects.filter(id__gte=40, id__lt=400500).all()); print "Took
%ss"%(time.time() - _t)Took 0.0467309951782s>>> _t =
time.time(); _res = map(lambda x: x,
Post.objects.all()[40:400500]); print "Took %ss"%(time.time() -
_t)Took 1.05785298347s>>>



On Sun, Feb 20, 2011 at 10:35 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Also, this snippet isn't directly related, but it does show the methods we
> used to paginate through 50 million rows, with query times of below 0.5
> seconds :) It uses the same method that was in my first suggestion (the ID
> max thing)
>
> http://djangosnippets.org/snippets/2277/
>
> Cal
>
> On Sun, Feb 20, 2011 at 10:26 PM,  wrote:
>
>> That would have been my approach if I were to do that. So, we are now two
>> seeking the good way to get it done.
>> Hello People,
>> Galago and I have the same challenge, please help us.
>>
>> Sent from my BlackBerry wireless device from MTN
>> --
>> *From: * galago 
>> *Sender: * django-users@googlegroups.com
>> *Date: *Sun, 20 Feb 2011 14:24:37 -0800 (PST)
>> *To: *
>> *ReplyTo: * django-users@googlegroups.com
>> *Subject: *Re: Select x random rows from DB
>>
>> If i knew what is a good idea, I wouldn't aks here:D
>> I only know - that described method is DB killer :)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

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



Re: What will happen when a model I modified get saved.

2011-02-20 Thread delegbede
Hey Shawn,
I have been opportuned to have south installed on my pc but I must confess I 
have never understood its use. Now that its being mentioned in here, I think I 
am going to get into it and understand its use. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Shawn Milochik 
Sender: django-users@googlegroups.com
Date: Sun, 20 Feb 2011 14:30:04 
To: 
Reply-To: django-users@googlegroups.com
Subject: Re: What will happen when a model I modified get saved.

First, what are you trying to do?

1. The code you posted is not valid Python, because 'Object' is
capitalized. So you haven't actually even tried this, or it would have
blown up.
2. Adding 'y' to your subclass of Model does nothing with the
database, because y is not a subclass of one of the fields the model
class provides.
3. If you've created your database already using syncdb and then
changed the model, your database won't change. You need to use South
or destroy and re-create the database.

Shawn

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

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



Re: Select x random rows from DB

2011-02-20 Thread Christophe Pettus

On Feb 20, 2011, at 2:19 PM, galago wrote:

> What is the best way, to select X random rows from DB? I know that method: 
> .all().order_by('?')[:X] is not good idea.

The best way is to push it onto the DB, using a raw query:

random_results = Table.objects.raw("SELECT * FROM table ORDER BY 
random() LIMIT X")

--
-- Christophe Pettus
   x...@thebuild.com

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



How to display value from a sub model in the template

2011-02-20 Thread Chris
Hi !
 I have template page I'm trying to list all the player of a team, The
player model have 2 sub-model: playerVital and playerSkill.
The model playerVital has a one to one relation ship with the player
model and player skill have a foreign key to the player model.
 How can I show the value of the sub model when looping players in the
team object?
Showing value of the player model work fine but not the sub model.
I tried various syntax but nothing seem to work.

Thanks,
Chris

Here are the model and the template i'm building :
model.py
class Team(models.Model):
team_name = models.CharField(max_length=200)
def __unicode__(self):
return self.team_name

class Player(models.Model):
teamKey = models.ForeignKey(Team, blank=True, null=True)
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
def fullname(self):
return u'%s %s' % (self.first_name, self.last_name)
def __unicode__(self):
return self.fullname()

class PlayerVital(models.Model):
playerKey = models.OneToOneField(Player, primary_key=True)
position=models.CharField(max_length=2, choices=POSITION) #C/RW/LW/
D/G
hand= models.CharField(max_length=10, choices=HAND) #Left/Right
height= models.IntegerField()
weight= models.IntegerField()
nationality = models.CharField(max_length=200)


class PlayerSkills(models.Model):
SKILL_RANGE = zip( range(0,100), range(0,100))
playerKey = models.ForeignKey(Player)
skill_at_date = models.DateField('skill_date')
speed=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
strength=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
endurance=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)

template :
{{ object.team_name }}

{% if error_message %}{{ error_message }}{%
endif %}

{% csrf_token %}



Player Name


Position


speed


height


{% for player in object.player_set.all %}


{{ player.fullname }}  


{{ player.playerVitals.position }} 

 
{{ player.playerSkill.speed }}


{{ player.height }}   


{% endfor %}




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



Re: How to display value from a sub model in the template

2011-02-20 Thread Shawn Milochik
What are the related_name values you gave to the foreign key fields of
your related models?

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



Re: Filtering List based on a custom dropdown

2011-02-20 Thread Andre Terra
I'd also like some input on this, as I'm reaching a point of my project
where I'll have to deal with a similar issue. I was planning on using ajax,
which actually means keeping it simple IMHO, but I would really like to
follow best practice.

Should I make one query with a large subset of the data once and then just
filter it with jQuery? This seems to be the lighter approach in terms of DB
hits, but I'm not sure it's the right solution, specially considering I want
to be able to export the filtered data to a csv/xls format.

Any ideas would be greatly appreciated, I'm really in the dark on this.


Sincerely,
André Terra

On Tue, Feb 8, 2011 at 9:15 PM, SimpleDimple wrote:

> can anyone help or point me to some simple django based app that I can
> study to understand more ?
>
> On Feb 8, 2:07 am, SimpleDimple  wrote:
> > I can live w/o AJAX for now to keep it simple.
> >
> > What I am not clear is on how to do the postback from javascript ?  I
> > mean on what URL and pass on which variables ? and thru GET or POST or
> > shall i do form.submit()  ??
> >
> > On Feb 8, 1:45 am, Joel Goldstick  wrote:
> >
> > > On Mon, Feb 7, 2011 at 3:38 PM, SimpleDimple <
> farhandevelo...@gmail.com>wrote:
> >
> > > > I am new to django and building a school system but am experience
> > > > developer otherwise having firm grip over rails, php, .net and java.
> >
> > > > I have student table and in list I can see list of all students/
> > > > records in student table(pasted below is my code)
> >
> > > > what I want here is a custom dropdown listing the classes in school
> > > > from class table, and when you select/change the class the list of
> > > > students should get filtered accordinglycan someone please give
> me
> > > > hints or guide me a bit ?
> >
> > > > class StudentAdmin(admin.ModelAdmin):
> > > >fields= ['xclass', 'name', 'reg_no' , 'roll_no' ]
> > > >list_display  = ['xclass', 'name', 'reg_no' , 'roll_no' ]
> > > >list_filter   = ['name', 'reg_no' , 'roll_no' ]
> > > >search_fields = ['name', 'reg_no' , 'roll_no' ]
> >
> > > >form  =  StudentForm
> >
> > > >def queryset(self, request):
> > > >school_id = request.session['school_id']
> > > >qs = self.model._default_manager.filter(school=school_id)
> > > >return qs
> >
> > > >def save_model(self, request, obj, form, change):
> > > >school_id = request.session['school_id']
> > > >school = School.objects.get(id=school_id)
> > > >obj.school = school
> > > >obj.save()
> >
> > > > --
> > > > You received this message because you are subscribed to the Google
> Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-users@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
> >
> > > This topic has come up recently under different specifics.  When you
> change
> > > your filter (by selecting a specific class) you need to requery with
> that
> > > condition.  This can be done by submitting the form to get a new
> dataset, or
> > > by using AJAX style to have the data retrieved on the fly to repopulate
> your
> > > form.
> >
> > > --
> > > Joel Goldstick
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



objects added via inline not logged

2011-02-20 Thread Frank W. Samuelson


I have an class payment that links to households
class Payment(models.Model):
# Which household made this payment?
household = models.ForeignKey(Household)
...

and the household has a payment inline in the admin 
interface.


When I add a payment from the list of Payments, the first 
line of the new object's change history is the date, 
time, and user who created the object.
But when I add a payment as an inline on the page of a 
Household, there is no record made.  The history says,
"This object doesn't have a change history. It probably 
wasn't added via this admin site."


I would like to know which user created the payment 
regardless of how is was created.  Is there a way 
to get the admin interface to make a history for objects 
added via an inline?   Am I doing something wrong? 
Currently I'm using version 1.2.1.


Thanks for any help.

-Frank

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



Re: objects added via inline not logged

2011-02-20 Thread Karen Tracey
On Sun, Feb 20, 2011 at 9:39 PM, Frank W. Samuelson <
fr...@merrill-samuelson.com> wrote:

> I have an class payment that links to households
> class Payment(models.Model):
># Which household made this payment?
>household = models.ForeignKey(Household)
>...
>
> and the household has a payment inline in the admin interface.
>
> When I add a payment from the list of Payments, the first line of the new
> object's change history is the date, time, and user who created the object.
> But when I add a payment as an inline on the page of a Household, there is
> no record made.  The history says,
> "This object doesn't have a change history. It probably wasn't added via
> this admin site."
>
> I would like to know which user created the payment regardless of how is
> was created.  Is there a way to get the admin interface to make a history
> for objects added via an inline?   Am I doing something wrong? Currently I'm
> using version 1.2.1.
>

The admin does log the inline creation, however it is logged under the
Household object where it was added. So if you look at the History of the
related Household object, you will see the Payment added there.

Karen
-- 
http://tracey.org/kmt/

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



Re: What will happen when a model I modified get saved.

2011-02-20 Thread Shawn Milochik
On Sun, Feb 20, 2011 at 5:33 PM,   wrote:
> Hey Shawn,
> I have been opportuned to have south installed on my pc but I must confess I 
> have never understood its use. Now that its being mentioned in here, I think 
> I am going to get into it and understand its use.
> Sent from my BlackBerry wireless device from MTN
>

The docs on the project page are good:
http://south.aeracode.org/docs/

Check out the tutorial:
http://south.aeracode.org/docs/tutorial/index.html

Shawn

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



Integrating Django with Amazon's Database

2011-02-20 Thread ravi krishna
Hi,

Can somebody help me to integrate Django with Amazon's Database (SimpleDB).
Can we use SimpleDB like sqlite or mysql with Django? What are the process
involved in doing it ? It would be great help if someone could explain me or
send me some tutorial for doing it.

Thanks & Regards,

Ravi Krishna
My profiles: [image:
Facebook] [image:
LinkedIn]  [image:
Twitter] 


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



Re: Redirecting to last view after login.

2011-02-20 Thread keynesiandreamer
Thanks so much for the reply Scott. Wish I would have seen it a bit
sooner.

So I double checked my TEMPLATE_CONTEXT_PROCESSORS as you suggested:

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)

So that looks good.

Not sure how to check that I am overwriting it.

Thoughts?


On Jan 5, 9:16 am, "Scott Hebert (slaptijack)"
 wrote:
> I'm sorry you haven't gotten a response from anyone yet.
>
> From everything you've provided here, it looks like you're doing this
> exactly right. The key seems to be that request is not being set. I
> think you need to verify two things:
>
> 1) That django.core.context_processors.request is in your
> TEMPLATE_CONTEXT_PROCESSORS settings variable.
>
> 2) That you aren't overwriting the request variable accidentally with
> your own.
>
> Good luck!
>
> --
> Scott

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



RE: urls.py and views.generic issue

2011-02-20 Thread Chris Matthews
It also seems that the space preceding the caret ^ should not be there

So

^blog/ ^(?P\d{4})/$

Should be

^blog/^(?P\d{4})/$





-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of jnns
Sent: 20 February 2011 03:07
To: Django users
Subject: Re: urls.py and views.generic issue



Hi Antti,



the url patterns in the tutorial are not correct. The regular

expressions are not using character classes but merely plain

characters.



^blog/ ^(?Pd{4})/$

should be

^blog/ ^(?P\d{4})/$



Mind the backslash in \d{4}. This way we're matching for a sequence of

four digits and not for a sequence of four "d"s.



Regards,

jnns



On Feb 20, 12:57 am, Antti  wrote:

> The problem:

>

> I can't seem to get most of my urls that I type in my browser to math

> a url in my urls.py file.  I am currently doing Web Monkey's Blog

> Tutorial (http://www.webmonkey.com/2010/02/Get_Started_With_Django/)

> To date everything has worked but when I try to use the urls from the

> blog urls.py I get the following error:

>

> Using the URLconf defined in anttipetaisto.urls, Django tried these

> URL patterns, in this order:

>

> ^admin/doc/

> ^admin/

> ^blog/ (?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-w]

> +)/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-

> w]+)/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/$

> ^blog/ ^(?Pd{4})/(?P[a-z]{3})/$

> ^blog/ ^(?Pd{4})/$

> ^blog/ ^$

> ^tags/(?P[a-zA-Z0-9_.-]+)/$

> ^static_files/(?P.*)$

>

> The current URL, blog/2011/jan/20/things-learned-finland/, didn't

> match any of these.

>

> What I don't understand why this is saying that isn't a url match.

> Shouldn't it match the third one down?

>

> Thanks

>

> Antti



--

You received this message because you are subscribed to the Google Groups 
"Django users" group.

To post to this group, send email to django-users@googlegroups.com.

To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.

For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


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



Re: Python's 20th Birthday (well, public release birthday) Extravaganza Lunch Party!

2011-02-20 Thread Gabriel Gunderson
On Fri, Feb 18, 2011 at 2:12 PM, Gabriel Gunderson  wrote:
> We'll be gathering Monday to have pizza, giant subs, spam with eggs**,
> and a specially commissioned Python-themed cake by Joseph Hall of 3D
> TuxCake fame[2].


Heh, I thought I'd share a cake update.  We're going to need some help
eating it.   :)

"""
There are three tiers: 12", 10" and 8". Each tier is about 3 or 4
inches tall. The smallest tier is ginger ale-flavored with grenadine
mousse filling. The middle tier is Mountain Dew flavored with cherry
mousse filling. The large tier is chocolate orange with a chocolate
orange marquess filling. The ginger ale isn't as gingery and the Mr
Dew isn't as Dewey, but they're still both dang good. All tiers are
covered with white chocolate fondant. The top tier has the python logo
on top of it.
"""

Looks like Joseph might have outdone himself, again.

Pic:  http://bit.ly/LetEmEatCake

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



Re: Django API efficient enough for filtering tens of millions of records?

2011-02-20 Thread Sithembewena Lloyd Dube
Thanks Thomas :)

On Tue, Feb 15, 2011 at 11:16 AM, Thomas Weholt wrote:

> FYI: release version 0.5.0 of DSE yesterday. Source is available at
> https://bitbucket.org/weholt/dse and pypi.
>
> Regards,
> Thomas Weholt
>
> On Tue, Feb 15, 2011 at 10:10 AM, Sithembewena Lloyd Dube
>  wrote:
> > Hi Everyone,
> >
> > Coming back weeks later, to say thank you for your contributions. I got
> > quite sidetracked from this task, but I should report back on this soon.
> >
> > Thank you!
> >
> > On Wed, Jan 19, 2011 at 10:05 AM, Thomas Weholt  >
> > wrote:
> >>
> >> Bulk inserts are the way the go if you can. When inserting a bunch of
> >> data, avoid using the django orm. Do it in plain SQL. The overhead of
> >> creating django orm model instances is way too expensive. Alltough it
> >> may not be bulk insert the sense Nick mentioned above I wrote DSE [
> >> http://pypi.python.org/pypi/dse/0.3.1 ] for that exact purpose, to
> >> insert or update a bunch of data using plain SQL, but it hasn`t been
> >> tested much so don`t use it in production. The thing it solves, can be
> >> done in simple SQL;
> >>
> >> Use cursor.executemany("",  >> with params>).
> >>
> >> DSE takes care of creating SQL-statements for insert and updates based
> >> on your models, handles any default values you might have defined in
> >> your model, caches lists of params and executes cursor.executemany
> >> when the list of cached items reaches a specified limit. My experience
> >> is that the performance gain of this solution or a similar one is
> >> huge. Using cursor.executemany might be what Nick meant by bulk
> >> insert, but I think different DB backends handles it differently. I
> >> don`t know. Anyway, I've inserted many thousands of records using DSE
> >> and it takes a fraction of the time when compared to doing it with the
> >> orm.
> >>
> >>
> >> NB! DSE is a proof-of-concept project more than anything else. It
> >> needs a good re-write, extensive testing and docs, but it might be
> >> helpful.
> >>
> >> Thomas
> >>
> >>
> >>
> >>
> >>
> >> On Wed, Jan 19, 2011 at 2:35 AM, Nick Arnett 
> >> wrote:
> >> >
> >> >
> >> > On Tue, Jan 18, 2011 at 12:04 PM, Sithembewena Lloyd Dube
> >> >  wrote:
> >> >>
> >> >> Hi all,
> >> >>
> >> >> I am building a search app. that will query an API. The app. will
> also
> >> >> store search terms in a very simple table structure.
> >> >>
> >> >> Big question: if the app. eventually hit 10 million searches and I
> was
> >> >> storing every single search term, would the table hold or would I run
> >> >> into
> >> >> issues?
> >> >
> >> > As someone else said, 10 million records is no big deal for MySQL, in
> >> > principle.
> >> > However, you probably would do better to avoid all the overhead of a
> >> > database transaction for storing each of these.  I'm going to assume
> >> > that
> >> > there will be duplicates, especially if you normalize the queries.  It
> >> > would
> >> > make a lot more sense to log the queries into a text file, which has
> >> > extremely low overhead.  Then you'd periodically process the log
> files,
> >> > normalizing and eliminating duplicates, producing a bulk insert to
> load
> >> > into
> >> > the database.  Bulk inserts will be FAR more efficient than using
> >> > Django.
> >> > Nick
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Django users" group.
> >> > To post to this group, send email to django-users@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/django-users?hl=en.
> >> >
> >>
> >>
> >>
> >> --
> >> Mvh/Best regards,
> >> Thomas Weholt
> >> http://www.weholt.org
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/django-users?hl=en.
> >>
> >
> >
> >
> > --
> > Regards,
> > Sithembewena Lloyd Dube
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
>
>
>
> --
> Mvh/Best regards,
> Thomas Weholt
> http://www.weholt.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, vis