Re: Permalinks/get_absolute_url when an object has multiple URLs?

2010-03-09 Thread Xavier Ordoquy
Hi,

> Some of our more common models are shared throughout our app ecosystem
> and we frequently run into a problem with get_absolute_url/permalink/
> etc of generating required URLs, in particular looking at user A's
> interaction with a model vs user B's that may occur in a completely
> separate part of the app.
> 
> Example:
> 
> We track a list of Office objects. Several users interact with these
> office objects via /a/offices/id/ URLs.
> 
> The public interacts with Office objects at /b/washington/ (the slug
> of the office).
> 
> While not ideal in the sense that 1 "object" == 1 URL, surely I'm not
> the only one with this issue -- I want to use the URL tools in Django
> -- but from what I've read/seen/tested/used, this is outside of the
> machinery Django provides.

Why not simply define another function like get_absolute_url_for_user_B which 
would reverse your url for user B ?
If you're having different urls for the object, you'll have somewhere that 
tells which one to use anyway.

Regards,
Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 registration not showing logged in on all pages

2010-03-09 Thread Duvalfan23
This worked like a charm!! Thanks!!

On Mar 9, 12:47 am, Kenneth Gonsalves  wrote:
> On Tuesday 09 Mar 2010 11:01:59 am Duvalfan23 wrote:
>
> > Not that Im aware of. Im using the built in auth methods as of now for
> > login and logout. Im kind of a django newbie. Im not quite sure what
> > you mean by that. Ill try to go look up some documentation on it But
> > if you have any great info on that please let me know. Thanks!!
>
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSShttp://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Newbie question: upgrade to python 2.6: cannot (re)connect to Django?

2010-03-09 Thread BobAalsma
On this machine (MacPro, OS X 10.5.8) I have installed and started
working with Django. I wanted to upgrade to Pyhton 2.6. Installed from
http://www.python.org/download/ (downloaded 2.6.4 Mac Installer Disk
Image). Seems to work properly. Then wanted to use Django again. Can't
seem to connect to this.
Re-downloaded Django and still does not work:
MacPro1:Downloads$ ls
Django-1.1.1.tar
MacPro1:Downloads$ sudo python setup.py install
Password:
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/
Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such
file or directory

I can't find anywhere how to proceed.
Please help?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: tutorial --> deploy snag

2010-03-09 Thread Joakim Hove
Hello,

I __think__ you must add the path industtromatic_com in your wsgi
settings file,

> The line
> os.environ['DJANGO_SETTINGS_MODULE'] = 'industromatic_com.settings'
> refers to a dir I made, /home/john/WEBprojects/industromatic_com, that I 
> copied the
> contents of mysite into.  mysite as it was at the end of the tuturial.

i.e. something like:

import sys
sys.path.append( "/home/john/WEBprojects/industromatic_com" )
os.environ["DJANGO_SETTINGS_MODULE"] = 'industromatic_com.settings'


HTH - Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



tutorial --> deploy snag

2010-03-09 Thread John Griessen

I've worked through http://docs.djangoproject.com/en/1.1/intro/tutorial01/ to 
tutorial04
then read up on WSGI, got that to go with a hello world output.

Then I decided to copy the tutorial to a name of a site I want to test over the 
internet -- one with
DNS pointing to its name, industromatic.com.  I made this directory
on my local machine, not over internet yet.

The line
os.environ['DJANGO_SETTINGS_MODULE'] = 'industromatic_com.settings'
refers to a dir I made, /home/john/WEBprojects/industromatic_com, that I copied 
the
contents of mysite into.  mysite as it was at the end of the tuturial.

I changed mysite to industromatic_com everywhere in the files and the project 
still runs fine
if I do
python manage.py runserver  and browse  http://127.0.0.1:8000/polls/1

but when I use the apache2  setup for 
industromatic.com

I get errors (from the debug = True output), that always contain this that I 
think is a clue:

Exception Value:No module named polls.urls

/usr/lib/pymodules/python2.5/django/utils/importlib.py in import_module

35.  __import__(name)

name 'polls.urls'

Does that give anyone a clue?  I'm thinking I need more on the python path, or 
cloning a project
by copying and text processing is bad to do...

Thanks,

John

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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.



Permalinks/get_absolute_url when an object has multiple URLs?

2010-03-09 Thread Ceph
Some of our more common models are shared throughout our app ecosystem
and we frequently run into a problem with get_absolute_url/permalink/
etc of generating required URLs, in particular looking at user A's
interaction with a model vs user B's that may occur in a completely
separate part of the app.

Example:

We track a list of Office objects. Several users interact with these
office objects via /a/offices/id/ URLs.

The public interacts with Office objects at /b/washington/ (the slug
of the office).

While not ideal in the sense that 1 "object" == 1 URL, surely I'm not
the only one with this issue -- I want to use the URL tools in Django
-- but from what I've read/seen/tested/used, this is outside of the
machinery Django provides.

Suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Serializing objects with a many-to-many reference

2010-03-09 Thread Russell Keith-Magee
On Wed, Mar 10, 2010 at 1:57 AM, Jesus Mager  wrote:
> 2010/3/2 Russell Keith-Magee :
>> On Wed, Mar 3, 2010 at 12:46 AM, Jim N  wrote:
>>> Hi,
>
>> The short answer is you can't - at least, not out of the box. This is
>> a feature that has been proposed several times [1] in the past.
>> Django's serializers are primarily designed for use in the testing
>> system, where the exact structure of the serialized output isn't as
>> important.
>>
>> At some point, I'm hoping to be able to do a full teardown of the
>> serialization infrastructure to make it completely configurable. This
>> would enable features like [1], along with many others.
>>
>> In the interim, there is a third-party project called "Django Full
>> Serializers" [2] that includes this sort of functionality.
>>
>> [1] http://code.djangoproject.com/ticket/4656
>> [2] http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers
>>
>> Yours,
>> Russ Magee %-)
>>
>
>
> Hi russell!
>
> I'm trying to gather all things that are wanted and requested for
> customizable serialization. I see custom in-depth serialization is
> requested. But, what other features are wanted?

The ideal end goal is that you should be able to output any object (or
list of objects), in any format, to any depth, with any additional
information. This includes, but is not limited to:

 * Serializing nested structures (of arbitrary depth)
 * Serializing subsets of model attributes
 * Serializing non-database attributes/properties
 * Serialized output that doesn't match the current default output
format (i.e., a model in JSON doesn't have to be {"pk": XX, "model":
"myapp.foo", "fields": {...}} )
 * Serialized output format that can change on a per-model basis
 * Serialized output format that can change based on where in the
output tree the object is located (e.g., output the full User object
if it's included from within model X, but only output the username if
its included from within model Y)

In short, we want serialization to be flexible. If we've made a design
decision with Django's serializers, that decision should be
customizable as an end user.

Yours
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: NullBooleanField save error in Admin

2010-03-09 Thread Karen Tracey
Sounds like a bug. I don't recall seeing one like it reported before, so if
you could open a ticket for it that would be appreciated.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: radio on admin

2010-03-09 Thread Vinuta Shetty
Hello,

Try using a CharField instead of IntegerField. This is how I used and
it works for me.

tipo = models.CharField(max_length=1,
                               choices = IMAGEM_TIPOS_CHOICES,
                                )
Thanks

On Mar 8, 8:12 am, gustavo  wrote:
> Hello folks,
>
> I am having a hard time trying to use a radio button field on admin.
>
> I am using:
>
> tipo = models.IntegerField(
>                                max_length=1,
>                                choices = IMAGEM_TIPOS_CHOICES,
>                                )
>
> where IMAGEM_TIPOS_CHOICES is a list of tuples.
>
> Any light please?
>
> Thanks a lot!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



custom authentication for admin

2010-03-09 Thread Tim Arnold
Hi,
I've read about the custom authentication you can do so you can use
upstream validators for your views. And a snippet that helps do that
is here
http://www.djangosnippets.org/snippets/1723/

But will that work for the admin panels? It doesn't look like it to
me...I have a database of users behind a firewall so I can
authenticate just fine, but I need nearly all of the users (1000's) to
be able to add/edit/delete records.

I'd rather not write forms specifically for them since the admin is
exactly what I need to offer.

Is there a way to authenticate and pass it on to the admin views?
thanks,
--Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 can I manually use RelatedFieldWidgetWrapper around a custom widget?

2010-03-09 Thread justind
Hello,

I've created a custom widget to replace the many to many widget found
in the admin. Its working well, but I lose the "add" button when I use
it. I see that the functionality is added by wrapping the widget in
the RelatedFieldWidgetWrapper, but I can't figure out how to implement
it. Essentially, my problem is the same as the user Julien who wrote
to this group in 2007 under the subject "Popup 'add another' and
custom widget in newforms-admin". (Actually I'm having the secondary
problem he lists too, where form is still spitting back Validation
errors even though the model specifies that this field is blank=True
null=True)

I noticed this solution here: 
http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/,
but it seems like using the built in RelatedFieldWidgetWrapper would
be the way to go to avoid any unexpected problems.

My Form code looks like this:

class EasyResourceAdminForm(forms.ModelForm):
files =
forms.ModelMultipleChoiceField(queryset=File.objects.none(),
widget=MySelect)

def __init__(self, *args, **kwargs):
super(EasyResourceAdminForm, self).__init__(*args, **kwargs)
self.fields['files'].queryset =
File.objects.filter(resource=self.instance.pk)

class Meta:
model = Resource

My AdminForm starts like this...

class ResourceAdmin(admin.ModelAdmin):
form = EasyResourceAdminForm

MySelect is a subclass of SelectMultiple and implements custom render
and render_options fields.

I tried watching the execution from PDB in a few places, but I get
lost quickly.

Any ideas?

Thanks,
Justin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



NullBooleanField save error in Admin

2010-03-09 Thread Ed Hagen
Hi,

I have a model field defined thus:

benefit = models.NullBooleanField()

In django 1.1 and 1.2 pre-alpha, nulls were displayed with a "?" icon
in list view. In the Admin change form, a pop-up menu appeared with 3
options (Unknown, Yes, No). Setting to "Unknown" and saving did not
generate any errors.

I then updated to django 1.2  beta 1 SVN-12738. Nulls are now
displayed with "(None)". When I try and set this field to "Unknown"
using the popup menu, and then save in the Admin, I get the following
error:

"This field cannot be blank."

I get this same error when I try and add a new record in the Admin.

I am using python 2.5.1 on Mac OS X and sqlite3.

Any insights into what is going on and how I can fix this would be
greatly appreciated.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Multi Queryset one Paginator

2010-03-09 Thread Mat
I was wondering if there is a way to put multiple querysets into one
paginator. Currently I have my querysets being chained together with
itertools. But i am unable to put the chained querysets into the
paginator. Does any one know how I can combine multiple paginators
into one or multiple querysets into one big queryset not a chain of
querysets?

thanks
mat

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Passing (validated) form content to the next view.

2010-03-09 Thread Joakim Hove
Sorry;

my attempts at interlacing ASCII art in the code did not exactly
aid readability. Here is the code section again, simplified:

--
def InputForm( forms.Form ):
 name = forms.CharField( max_length = 100)
 email = forms.EmailField( )


# This is the view called in 1 above (have omitted some csrf magic).
def initial_view( request ):
  if request.method == "GET":
   form = InputForm()
  else:
   form = InputForm( reques.POST )
   if form.is_valid():
return HttpResponseRedirect( "/last_chance/" , )
return render_to_response( "form_template.html" ,
request )

# In this view I would like to display the input the user entered in
# the previous form.
def last_chance_view( request ):
  return render_to_response()??

 
--

Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Passing (validated) form content to the next view.

2010-03-09 Thread Joakim Hove
Hello,

I am implementing a small system which (simplified) should be like
this:

1. The user enters some information in a form.
2. The form content is validated.
3. The user is redirected to a new page (pure HTML / form ??)
summarizing
the information in the first form, and given the choices:
 A: Go back and correct the information.
 B: Confirm that the information is correct. (In this case I plan
to hit the database with updated information).


Currently the code looks roughly like this:
--
def InputForm( forms.Form ):
 name = forms.CharField( max_length = 100)
 email = forms.EmailField( )


# This is the view called in 1 above (have omitted some csrf magic).
def initial_view( request ):
  if request.method == "GET":
   form = InputForm()
  else:
   form = InputForm( reques.POST )
   if form.is_valid():
return HttpResponseRedirect( "/last_chance/" , )
>\
return render_to_response( "form_template.html" ,
request )   |
 
|
 
|
# In this view I would like to display the input the user entered in
the previous form.  |
def last_chance_view( request ):
<--/
  return render_to_response()??
--

Now; the question I have is how to pass the validated input values
(i.e. name and email) from initial_view() on to the last_chance_view()
(as indicated with the ASCII arrow in the code above).

Joakim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Extending a custom built API

2010-03-09 Thread Nick
Thanks for the reference and critique, Tom. Currently this is an
internal API to connect two systems together. The query structure was
requested from one set of developers. I am planning on setting up an
external API for another project and this will be helpful in creating
a standard structure.

On Mar 9, 11:03 am, Tom Evans  wrote:
> On Mon, Mar 8, 2010 at 10:41 PM, Nick  wrote:
> > I am working on an api that outputs a list of JSON based on certain
> > criteria.  Currently if someone 
> > entershttp://example.mysite/slideshows/api?id=1
> > it returns a JSON serialized output of the slideshow with that ID.
>
> > What I would like to do is allow for multiple ids, so
> >http://example.mysite/slideshows/api?id=1,2,5,9,10will pull in JSON
> > values for each of those slideshows.
>
> > I'd like to keep from using a third party API solution, I have checked
> > them out and I like the customization with the hand built process
>
> > I am doing everything through a get process in a view, here it is:
>
> > def slideshowAPI2(request):
> >    error = False
> >    if 'id' in request.GET and request.GET['id']:
> >        id = request.GET['id']
> >        object = slideshow.objects.get(pk=id)
> >        return render_to_response('slideshow.json',
> >            {'object': object, 'id':id})
> >    if 'year' in request.GET and request.GET['year']:
> >        year = request.GET['year']
> >        object = serializers.serialize("json",
> > slideshow.objects.filter(publishdate__year=year))
> >        html = "%s" % object
> >        return HttpResponse(html)
> >    else:
> >        error = True
> >        return render_to_response('slideshow.json', {'error': True})
>
> Just a mild critique:
>
> http://example.mysite/slideshows/api?id=1,2,5,9,10
>
> This is not the usual or typical way to pass a list of values into a
> url query string. Typically, you would specify the id argument
> multiple times in the query string. This is how your browser, a JS
> framework, django or anything that is designed to parse query strings
> would expect to receive a list of values. Eg:
>
> http://example.mysite/slideshows/api?id=1=2=5=9=10
>
> In django, you can retrieve a list of values passed in a query string
> like this with the getlist() method on QueryDict[1]. Eg:
>
> if 'id' in request.POST:
>   ids = request.POST.getlist('id')
>
> Cheers
>
> Tom
>
> [1]http://docs.djangoproject.com/en/1.1/ref/request-response/#django.htt...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySets - Reverse Look-Up for Index

2010-03-09 Thread Calaganne
Although it works in my interactive environment.. it does not work in
my actual script.. ??

On Mar 9, 7:02 pm, Calaganne  wrote:
> Hey,
>
> thanx for the reply! No, the bid is *not* ordered randomly, but you
> know what, your solution works anyway! ;) Test this and you'll notice
> that it works.. (still haven't figured out why!):
>
>  * bs = BID.objects.all ()
>  * idx=81; bid=bs[idx];
>  * bs.order_by ('?').filter (pk__lt=bid.id).count () ## == idx
>
> Can u explain this? I've checked even for *every* bid in bs if this
> condition holds for my sample, and it was true. My test routine was:
>
>  * for idx, bid in enumerate(bs):
>  *     idx, bs.order_by ('?').filter (pk__lt=bid.id).count () - idx ==
> 0
>
> .. strange.
>
> On Mar 7, 11:50 am, greatlemer  wrote:
>
> > if bids is ordered by index then you could just return
> > BID.objects.filter(...).filter(pk__lte=id).count() and that should be
> > what your after in one step (if I've understood the question
> > correctly).
>
> > --
> > G
>
> > On Mar 7, 7:10 am, Hasan Karahan  wrote:
>
> > > Hi,
>
> > > I'm wondering if there is an efficient way to look-up the index of a given
> > > object in a query-set? I'm using now the following approach:
>
> > > def get_index (id):
>
> > > bids = BID.objects.filter (..)
> > > obj2idx = dict (zip (bids, xrange (bids.count ()))
>
> > > bid = BID.objects.get (id=ID)
>
> > > return obj2idx (bid)
>
> > > This has a linear time processing.. is there a more efficient way to do 
> > > 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-us...@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: Pegar todos os objetos semelhantes em tempo d e execução

2010-03-09 Thread Masklinn
On 9 Mar 2010, at 19:05 , Romain Gaches wrote:
> 
> Le 9 mars 2010 à 18:42, Edgard Matos a écrit :
> 
>> Caros,
>> 
>> Tenho um object no django e quero pegar todos os objetos daquele mesmo tipo.
>> Sendo que eu não sei qual é o tipo deste objeto em tempo de execução.
>> 
>> Alguém sabe como fazer isso?
>> Obrigado!
> 
> Hi,
> 
> take a shot with this, it should work: your_object.__class__.objects.all() 
> 
> hope it helps.   

`your_object.__class__` would probably look better as `type(your_object)`

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Pegar todos os objetos semelhantes em tempo d e execução

2010-03-09 Thread Romain Gaches

Le 9 mars 2010 à 18:42, Edgard Matos a écrit :

> Caros,
> 
> Tenho um object no django e quero pegar todos os objetos daquele mesmo tipo.
> Sendo que eu não sei qual é o tipo deste objeto em tempo de execução.
> 
> Alguém sabe como fazer isso?
> Obrigado!

Hi,

take a shot with this, it should work: your_object.__class__.objects.all() 

hope it helps.
-- 
Romain Gaches
rom...@ssji.net



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySets - Reverse Look-Up for Index

2010-03-09 Thread Calaganne
Hey,

thanx for the reply! No, the bid is *not* ordered randomly, but you
know what, your solution works anyway! ;) Test this and you'll notice
that it works.. (still haven't figured out why!):

 * bs = BID.objects.all ()
 * idx=81; bid=bs[idx];
 * bs.order_by ('?').filter (pk__lt=bid.id).count () ## == idx

Can u explain this? I've checked even for *every* bid in bs if this
condition holds for my sample, and it was true. My test routine was:

 * for idx, bid in enumerate(bs):
 * idx, bs.order_by ('?').filter (pk__lt=bid.id).count () - idx ==
0

.. strange.

On Mar 7, 11:50 am, greatlemer  wrote:
> if bids is ordered by index then you could just return
> BID.objects.filter(...).filter(pk__lte=id).count() and that should be
> what your after in one step (if I've understood the question
> correctly).
>
> --
> G
>
> On Mar 7, 7:10 am, Hasan Karahan  wrote:
>
> > Hi,
>
> > I'm wondering if there is an efficient way to look-up the index of a given
> > object in a query-set? I'm using now the following approach:
>
> > def get_index (id):
>
> > bids = BID.objects.filter (..)
> > obj2idx = dict (zip (bids, xrange (bids.count ()))
>
> > bid = BID.objects.get (id=ID)
>
> > return obj2idx (bid)
>
> > This has a linear time processing.. is there a more efficient way to do 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-us...@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: Serializing objects with a many-to-many reference

2010-03-09 Thread Jesus Mager
2010/3/2 Russell Keith-Magee :
> On Wed, Mar 3, 2010 at 12:46 AM, Jim N  wrote:
>> Hi,

> The short answer is you can't - at least, not out of the box. This is
> a feature that has been proposed several times [1] in the past.
> Django's serializers are primarily designed for use in the testing
> system, where the exact structure of the serialized output isn't as
> important.
>
> At some point, I'm hoping to be able to do a full teardown of the
> serialization infrastructure to make it completely configurable. This
> would enable features like [1], along with many others.
>
> In the interim, there is a third-party project called "Django Full
> Serializers" [2] that includes this sort of functionality.
>
> [1] http://code.djangoproject.com/ticket/4656
> [2] http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers
>
> Yours,
> Russ Magee %-)
>


Hi russell!

I'm trying to gather all things that are wanted and requested for
customizable serialization. I see custom in-depth serialization is
requested. But, what other features are wanted?

-- 
Jesus Mager
[www.h1n1-al.blogspot.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-us...@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 use pre-built HTML forms in Django

2010-03-09 Thread MMRUser
So as per your knowledge can u suggest a proper way of getting data
from a form but not as mentioned in http://www.djangobook.com/en/2.0/chapter07/
that way is too rusty.

Thanks.

On Mar 9, 7:28 pm, rebus_  wrote:
> On 9 March 2010 15:22, MMRUser  wrote:
>
>
>
> > The problem I's having is that my HTML form depends upon lot of
> > external resources like javascript validation libraries and lots of
> > css on fields (and some may differ from each other), and I think that
> > I don't need to use re-usable templates because I just want to design
> > a one simple form so there's only one HTML file.Do you think that is
> > it ok to just ignore the Django's template system and get along with
> > the normal way.
>
> > On Mar 9, 2:32 pm, rebus_  wrote:
> >> On 9 March 2010 05:54, MMRUser  wrote:
>
> >> > Thanks another doubt,what about the css mappings class="field text
> >> > medium" do they also need to include in the class definition in
> >> > Django.
>
> >> > On Mar 9, 9:21 am, rebus_  wrote:
> >> >> On 9 March 2010 05:04, MMRUser  wrote:
>
> >> >> > I have an pre-built HTML form (means I design the HTML form
> >> >> > separately) and I need to reuse it with Django form class
> >> >> > (django.forms), So how do I incorporate my HTML form with Django form
> >> >> > class. for example
>
> >> >> > HTML:
>
> >> >> > 
> >> >> >  
> >> >> >  Username
> >> >> >  *
> >> >> >  
> >> >> >  
> >> >> >  
> >> >> >  
> >> >> > 
>
> >> >> > How do I map this HTML in to Django form definition, I know that it
> >> >> > can be done by modifying Django form fields according to this HTML.
> >> >> > But I guess it's a time consuming approach,so I would like to know
> >> >> > that is there any easy and time saving solutions for this issue.
>
> >> >> > Thanks.
>
> >> >> > --
> >> >> > You received this message because you are subscribed to the Google 
> >> >> > Groups "Django users" group.
> >> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> >> > To unsubscribe from this group, send email to 
> >> >> > django-users+unsubscr...@googlegroups.com.
> >> >> > For more options, visit this group 
> >> >> > athttp://groups.google.com/group/django-users?hl=en.
>
> >> >> Well usually you first create a form in django and use its instance to
> >> >> generate the HTML.
>
> >> >> You can also write the HTML by yourself and all you need to be careful
> >> >> of is that name and id attributes of you inputs and input type are
> >> >> same as in the class you define.
>
> >> >> Your HTML corresponds to:
>
> >> >> class MyForm(forms.Form):
> >> >>    Field11 = forms.CharField(label="Username",  max_length=255)
>
> >> >> I highly recommend to first setup a form class then write HTML and
> >> >> making form fields have more sensible names then Field11.
>
> >> >> Also i suggest these links as further reading:
>
> >> >>http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangop...
>
> >> > --
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to 
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/django-users?hl=en.
>
> >> No, CSS classes are not defined in form class (as far as i know).
>
> >> I would suggest using reusable form templates [1] and putting the CSS
> >> classes on field wrappers for example.
>
> >> This is what you are interested in:
>
> >>http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-temp..
>
> >> Which ever approach you decide to use is valid, but writing a bunch of
> >> your own HTML for forms takes more time but is also more customisable,
> >> on the other hand using shortcut methods such as "as_p" [1] or
> >> "as_table" [2] is faster but you have less control over the outputted
> >> HTML.
>
> >> [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
> >> [2]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> Well, if you need a high level of customization you can write your own
> HTML for forms of course.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit 

Pegar todos os objetos semelhantes em tempo de execu ção

2010-03-09 Thread Edgard Matos
Caros,

Tenho um object no django e quero pegar todos os objetos daquele mesmo tipo.
Sendo que eu não sei qual é o tipo deste objeto em tempo de execução.

Alguém sabe como fazer isso?
Obrigado!

-- 
Atenciosamente,

Edgard Matos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 server side ajax vallidation

2010-03-09 Thread Shawn Milochik


On Mar 9, 2010, at 12:19 PM, MMRUser wrote:


Is there no one???



Nobody who wants to do your work for you? Maybe. Especially when you  
end your e-mail with "Your valuable corporation [sic] is expected."


Perhaps, if you write a short, easy-to-read e-mail with a very clear  
question that can be answered, someone will help you.


However, what you're trying to do is very common and you should do a  
Google search on how to do it. You will find the answers there. If you  
have trouble with that, report back with what you've tried and exactly  
which error (or unexpected behavior) you're experiencing.


Generally, if someone can easily read and understand your question,  
and it's phrased in such a way that a couple of sentences can answer  
you, they will. A good bunch of smart, generous people participate in  
this list. But you have to make it easy for them for best results.  
Remember that this is an all-volunteer army.


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-us...@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: radio on admin

2010-03-09 Thread gustavo
Ok Daniel!

The model is:

class Imagem(models.Model):
""" Várias Imagens são relativas a um Paciente """
IMAGEM_LATERAL = '1'
IMAGEM_FRONTAL = '2'
IMAGEM_PERFIL = '4'

IMAGEM_TIPOS_CHOICES = (
  (IMAGEM_LATERAL, _('Imagem lateral')),
  (IMAGEM_FRONTAL, _('Imagem frontal')),
  (IMAGEM_PERFIL, _('Imagem do perfil')),
)

class Meta:
ordering = ('paciente', 'titulo',)
verbose_name = _('Imagem')
verbose_name_plural = _('Imagens')

paciente = models.ForeignKey('Paciente')
titulo = models.CharField(max_length=100)
slug = models.SlugField(
max_length=100,
blank=True,
unique=True
)
descricao = models.TextField(blank=True)
original = models.ImageField(
 null = True,
 blank = True,
 upload_to = 'galeria/original',
 )
thumbnail = models.ImageField(
 null = True,
 blank = True,
 upload_to = 'galeria/thumbnail',
 )
publicacao = models.DateTimeField(
  default = datetime.now(),
  blank = True,
  )

tipo = models.CharField(
choices = IMAGEM_TIPOS_CHOICES,
max_length = 1,
)

def __unicode__(self):
return self.titulo

def get_absolute_url(self):
return reverse('imagem', kwargs={'slug': self.slug}) #nome
imagem ligado ao imagem do galeria/urls.py

And the ModelAdmin:

class AdminImagem(admin.ModelAdmin):

list_display = ('paciente','titulo','tipo')
list_filter = ('paciente','tipo',)
search_fields = ('titulo','descricao',)
radio_fields = {"tipo": admin.VERTICAL}

Thanks a lot!

On 9 mar, 13:23, Daniel Roseman  wrote:
> On Mar 8, 4:36 pm, gustavo  wrote:
>
> > Sure Daniel,
>
> > I have the admin showing only the "tipo"s label, not the choices!
>
> What are the choices? Honestly, it would be easier if you gave more
> than a single line of code here.
> --
> 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-us...@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: radio on admin

2010-03-09 Thread gustavo
Ok Daniel!

The model is:

class Imagem(models.Model):
""" Várias Imagens são relativas a um Paciente """
IMAGEM_LATERAL = '1'
IMAGEM_FRONTAL = '2'
IMAGEM_PERFIL = '4'

IMAGEM_TIPOS_CHOICES = (
  (IMAGEM_LATERAL, _('Imagem lateral')),
  (IMAGEM_FRONTAL, _('Imagem frontal')),
  (IMAGEM_PERFIL, _('Imagem do perfil')),
)

class Meta:
ordering = ('paciente', 'titulo',)
verbose_name = _('Imagem')
verbose_name_plural = _('Imagens')

paciente = models.ForeignKey('Paciente')
titulo = models.CharField(max_length=100)
slug = models.SlugField(
max_length=100,
blank=True,
unique=True
)
descricao = models.TextField(blank=True)
original = models.ImageField(
 null = True,
 blank = True,
 upload_to = 'galeria/original',
 )
thumbnail = models.ImageField(
 null = True,
 blank = True,
 upload_to = 'galeria/thumbnail',
 )
publicacao = models.DateTimeField(
  default = datetime.now(),
  blank = True,
  )

tipo = models.CharField(
choices = IMAGEM_TIPOS_CHOICES,
max_length = 1,
)

def __unicode__(self):
return self.titulo

def get_absolute_url(self):
return reverse('imagem', kwargs={'slug': self.slug}) #nome
imagem ligado ao imagem do galeria/urls.py

And the ModelAdmin:

class AdminImagem(admin.ModelAdmin):

list_display = ('paciente','titulo','tipo')
list_filter = ('paciente','tipo',)
search_fields = ('titulo','descricao',)
radio_fields = {"tipo": admin.VERTICAL}

Thanks a lot!

On 9 mar, 13:23, Daniel Roseman  wrote:
> On Mar 8, 4:36 pm, gustavo  wrote:
>
> > Sure Daniel,
>
> > I have the admin showing only the "tipo"s label, not the choices!
>
> What are the choices? Honestly, it would be easier if you gave more
> than a single line of code here.
> --
> 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-us...@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 server side ajax vallidation

2010-03-09 Thread MMRUser
Is there no one???

On Mar 9, 8:18 pm, MMRUser  wrote:
> Hi,
>
> Recently I'm trying to implement a simple Django application that
> include one server side AJAX validation, it's a simple form input
> field (username). I have used a pre-built in line AJAX validation
> mechanism which uses jQuery. So the code goes like this
>
> HTML snippet
>
> 
>
> Username: class="validate[required,custom[noSpecialCaracters],length[0,20],ajax[ajaxUser]]"
> type="text" name="user" id="user" />
>
> 
> 
>
> The server side code snippet (embedded in to a php script)
>
> /* RECEIVE VALUE */
> $validateValue=$_POST['validateValue'];
> $validateId=$_POST['validateId'];
> $validateError=$_POST['validateError'];
>
>     /* RETURN VALUE */
>     $arrayToJs = array();
>     $arrayToJs[0] = $validateId;
>     $arrayToJs[1] = $validateError;
>
> if($validateValue =="testname"){        // validate??
>     $arrayToJs[2] = "true";         // RETURN TRUE
>     echo
> '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';          //
> RETURN ARRAY WITH success}else{
>
>     for($x=0;$x<100;$x++){
>         if($x == 99){
>             $arrayToJs[2] = "false";
>             echo
> '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';      // RETURN
> ARRAY WITH ERROR
>         }
>     }
>
> }
>
> So I have some questions to ask from you people
>
> How do I get the user name from the input field in to the back end?(in
> order to use in Django environment)
>
> Do I need to get JSON support in Python?
>
> I think the server side script snippet already does a big part
> (passing the value to the backend as a JSON object) but I want to know
> how to use this in my Python code,and this is my first time using
> jQuery and I do need to use this same exact validation library. Your
> valuable corporation is expected.
>
> Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-weave needs contribution...

2010-03-09 Thread Jens Diemer

Am 08.03.2010 07:44, schrieb Rizwan Mansuri:

  I am happy to help you but my experience with django is very much like
starting level. Is that something helps you?


You are welcome ;)

--
Mfg.

Jens Diemer



http://www.jensdiemer.de

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Extending a custom built API

2010-03-09 Thread Tom Evans
On Mon, Mar 8, 2010 at 10:41 PM, Nick  wrote:
> I am working on an api that outputs a list of JSON based on certain
> criteria.  Currently if someone enters 
> http://example.mysite/slideshows/api?id=1
> it returns a JSON serialized output of the slideshow with that ID.
>
> What I would like to do is allow for multiple ids, so
> http://example.mysite/slideshows/api?id=1,2,5,9,10 will pull in JSON
> values for each of those slideshows.
>
> I'd like to keep from using a third party API solution, I have checked
> them out and I like the customization with the hand built process
>
> I am doing everything through a get process in a view, here it is:
>
>
> def slideshowAPI2(request):
>    error = False
>    if 'id' in request.GET and request.GET['id']:
>        id = request.GET['id']
>        object = slideshow.objects.get(pk=id)
>        return render_to_response('slideshow.json',
>            {'object': object, 'id':id})
>    if 'year' in request.GET and request.GET['year']:
>        year = request.GET['year']
>        object = serializers.serialize("json",
> slideshow.objects.filter(publishdate__year=year))
>        html = "%s" % object
>        return HttpResponse(html)
>    else:
>        error = True
>        return render_to_response('slideshow.json', {'error': True})
>

Just a mild critique:

http://example.mysite/slideshows/api?id=1,2,5,9,10

This is not the usual or typical way to pass a list of values into a
url query string. Typically, you would specify the id argument
multiple times in the query string. This is how your browser, a JS
framework, django or anything that is designed to parse query strings
would expect to receive a list of values. Eg:

http://example.mysite/slideshows/api?id=1=2=5=9=10

In django, you can retrieve a list of values passed in a query string
like this with the getlist() method on QueryDict[1]. Eg:

if 'id' in request.POST:
  ids = request.POST.getlist('id')


Cheers

Tom

[1] 
http://docs.djangoproject.com/en/1.1/ref/request-response/#django.http.QueryDict.getlist

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Re: Secret key

2010-03-09 Thread Henrik Genssen
the session e.g. depends on this key

regards

Hinnack

>reply to message:
>date: 09.03.2010 15:20:38
>from: "rebus_" 
>to: django-users@googlegroups.com
>subject: Re: Secret key
>
>On 9 March 2010 15:16, Joan Miller  wrote:
>> For what is used the key `SECRET_KEY`?
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>>
>
>A secret key for this particular Django installation. Used to provide
>a seed in secret-key hashing algorithms. Set this to a random string
>-- the longer, the better. django-admin.py startproject creates one
>automatically.
>
>http://docs.djangoproject.com/en/dev/ref/settings/#secret-key
>
>-- 
>You received this message because you are subscribed to the Google Groups 
>"Django users" group.
>To post to this group, send email to django-us...@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-us...@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: Populating a ManyToMany field

2010-03-09 Thread Laereom
Awesome, thanks.  I have been using The Django Book as my sole
documentation, which was quite foolish of me.  That gave me exactly
what I needed -- sorry for not remembering to check the actual docs
first!

On Mar 9, 8:19 am, Daniel Roseman  wrote:
> On Mar 9, 4:15 pm, Laereom  wrote:
>
>
>
>
>
> > I have a model, Response, which has a ManyToMany field with the model
> > Question named 'questionid'.  When I create an instance of response
> > like this:
> > response = Response(questionid=question,
> > blah,
> > blah
> > )
>
> > I receive the following error:
> > TypeError at /answer
> > 'questionid' is an invalid keyword argument for this function
>
> > It would seem, then, that although this is how one assigns normal
> > fields, ManyToMany fields have a special syntax -- Chapter 10 does
> > state this, and gives information on how to access things with
> > ManyToMany and ForeignKey attributes, but no information on actually
> > setting them that I can find.
>
> > Anyone care to help me out?
>
> Anything wrong with the very fine 
> documentation?http://docs.djangoproject.com/en/1.1/ref/models/relations/
> --
> 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-us...@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: radio on admin

2010-03-09 Thread Daniel Roseman
On Mar 8, 4:36 pm, gustavo  wrote:
> Sure Daniel,
>
> I have the admin showing only the "tipo"s label, not the choices!
>

What are the choices? Honestly, it would be easier if you gave more
than a single line of code here.
--
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-us...@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: Populating a ManyToMany field

2010-03-09 Thread Daniel Roseman
On Mar 9, 4:15 pm, Laereom  wrote:
> I have a model, Response, which has a ManyToMany field with the model
> Question named 'questionid'.  When I create an instance of response
> like this:
> response = Response(questionid=question,
> blah,
> blah
> )
>
> I receive the following error:
> TypeError at /answer
> 'questionid' is an invalid keyword argument for this function
>
> It would seem, then, that although this is how one assigns normal
> fields, ManyToMany fields have a special syntax -- Chapter 10 does
> state this, and gives information on how to access things with
> ManyToMany and ForeignKey attributes, but no information on actually
> setting them that I can find.
>
> Anyone care to help me out?

Anything wrong with the very fine documentation?
http://docs.djangoproject.com/en/1.1/ref/models/relations/
--
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-us...@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 a ManyToMany field

2010-03-09 Thread Laereom
I have a model, Response, which has a ManyToMany field with the model
Question named 'questionid'.  When I create an instance of response
like this:
response = Response(questionid=question,
blah,
blah
)

I receive the following error:
TypeError at /answer
'questionid' is an invalid keyword argument for this function

It would seem, then, that although this is how one assigns normal
fields, ManyToMany fields have a special syntax -- Chapter 10 does
state this, and gives information on how to access things with
ManyToMany and ForeignKey attributes, but no information on actually
setting them that I can find.

Anyone care to help me out?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 works django

2010-03-09 Thread serek
Hi

I am quite new in django. Could you explain me how django process
incoming request?
I have coded in php before, and there every request was like script
starts again (read config file, connect db, etc). in django it seems
different ;) and I do not understand it well yet. I will thankfull for
information, links, etc.

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Does anybody meet this strange Error

2010-03-09 Thread Forrest Liu
Hi,

I am struck with this strange error message:

AttributeError at /products/

'function' object has no attribute 'objects'

Request Method:GET
Request URL:http://127.0.0.1:8000/products/
Exception Type:AttributeError
Exception Value:

'function' object has no attribute 'objects'

Exception Location:E:\workspace\biotech\biotech\..\biotech\bio\views.py in
product, line 35

my views.py:

def product(request):
products = product.objects.all().order_by('name')
return
object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)

my model.py:

*
class product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True)
def __unicode__(self):
return self.name


and my index.html is :

{% for n in object_list %}

{{n.name}}

{% endfor %}

my Django version:1.1.1
python version: 2.6

Could you be so kind to give me some help,Thank you

*
--

Best regards,
Forrest

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 get current session user in models.py?

2010-03-09 Thread Shawn Milochik


On Mar 9, 2010, at 10:37 AM, James Bennett wrote:

On Tue, Mar 9, 2010 at 8:47 AM, Shawn Milochik   
wrote:
I wonder if this is something that might end up in Django as a  
built-in

feature at some point. It comes up regularly on this list.


Were I to sit here all morning doing nothing but typing, I wouldn't be
able to say "no" enough times to that.

If you need access to the user somewhere, write a function or method
which takes the user as an argument, and have your view call that
function or method, passing the user. This is approximately eighty
billion times simpler than coming up with threadlocal hacks to try to
create a magic global user variable, results in cleaner,
easier-to-understand code, reduces the likelihood of
difficult-to-track bugs in the code and, best of all, is a perfectly
obvious way to accomplish the task.

And, in all seriousness, when even the page you've linked to says that
it's not a good solution and should be avoided, why do you insist on
continuing to use it? One begins to suspect that some malevolent
entity has been going around magically crippling the fingers of
programmers in such a way that they're no longer capable of writing a
method signature including an argument named "user".


--
"Bureaucrat Conrad, you are technically correct -- the best kind of  
correct."


--



In my particular case, the purpose was to be able to have an audit log  
of changes made to a model, knowing who made the changes, without  
having to change all the models and views. I asked around on this list  
and nobody had a solution for doing this Someone pointed me to the  
threadlocals page on the official wiki. In a typical case, a user  
performing an action on a page results in methods being called on a  
model, some of which cause other model instances to be created or  
updated. Passing the user around 100% of the time would result in  
quite a bit of repeated code, and would require every model and every  
view in every application to be touched.


I'm not saying this to refute your points. I'm saying this because if  
there's a better way to do this then I'd like to know it. If there's  
something glaringly obvious that I'm missing, do let me know. Remember  
that not everyone who works with Django understands it as broadly and  
in as much depth as you, and realize that just because I may be doing  
something obviously stupid to you doesn't necessarily mean that I'm  
being intentionally thick.


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-us...@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 get current session user in models.py?

2010-03-09 Thread James Bennett
On Tue, Mar 9, 2010 at 8:47 AM, Shawn Milochik  wrote:
> I wonder if this is something that might end up in Django as a built-in
> feature at some point. It comes up regularly on this list.

Were I to sit here all morning doing nothing but typing, I wouldn't be
able to say "no" enough times to that.

If you need access to the user somewhere, write a function or method
which takes the user as an argument, and have your view call that
function or method, passing the user. This is approximately eighty
billion times simpler than coming up with threadlocal hacks to try to
create a magic global user variable, results in cleaner,
easier-to-understand code, reduces the likelihood of
difficult-to-track bugs in the code and, best of all, is a perfectly
obvious way to accomplish the task.

And, in all seriousness, when even the page you've linked to says that
it's not a good solution and should be avoided, why do you insist on
continuing to use it? One begins to suspect that some malevolent
entity has been going around magically crippling the fingers of
programmers in such a way that they're no longer capable of writing a
method signature including an argument named "user".


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Secret key

2010-03-09 Thread rebus_
On 9 March 2010 15:16, Joan Miller  wrote:
> For what is used the key `SECRET_KEY`?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

A secret key for this particular Django installation. Used to provide
a seed in secret-key hashing algorithms. Set this to a random string
-- the longer, the better. django-admin.py startproject creates one
automatically.

http://docs.djangoproject.com/en/dev/ref/settings/#secret-key

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Secret key

2010-03-09 Thread Joan Miller
For what is used the key `SECRET_KEY`?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 view the admin page through the browser

2010-03-09 Thread Shawn Milochik
Something is broken in your code. If you set DEBUG = True, you'll find  
out what. But since it's False, it is hiding that information for  
security reasons. It tries to display an error page to the browser,  
and it expects a template to exist called 500.html to show to your  
poor, out-of-luck user.


If you set up the ADMINS tuple in settings.py properly it should also  
e-mail you the detailed error information.


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-us...@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 get current session user in models.py?

2010-03-09 Thread Shawn Milochik
I wonder if this is something that might end up in Django as a built- 
in feature at some point. It comes up regularly on this list.


Here's what I used. It's a hack, but it works.

http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

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-us...@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.



Register multiple models to show in admin page

2010-03-09 Thread andrew_scfc
Hi,

I'm new to using Django and have come across some redundancy in my
implementation that I would like to irradicate.

I have defined several models in the models.py file as normal. I would
like to register all of my models to be available via the admin
interface. Currently I need to register models one by one in the
admin.py as show below:

from mysite.models import model1, model2, model3, model4, model5
from django.contrib import admin

admin.site.register(model1)
admin.site.register(model2)
admin.site.register(model3)
admin.site.register(model4)
admin.site.register(model5)


Is it possible to just register all models? Perhaps get hold of a
collection containing all the models. I am quite new to python so I
may have missed something quite simple, if so, I apologise.

Cheers
Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 view the admin page through the browser

2010-03-09 Thread Newbie
Dear all,

  Installed the Django framework in my local machine.
  Am able to create a models and inserted values into database.
  When I was trying to show the admin page it showed the following
error.

 Traceback (most recent call last):

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/core/servers/basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/core/servers/basehttp.py", line 651, in __call__
return self.application(environ, start_response)

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/core/handlers/base.py", line 134, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/core/handlers/base.py", line 166, in
handle_uncaught_exception
return callback(request, **param_dict)

  File "/home/thangappan/Non-Technical/Python//lib/python2.4/site-
packages/django/views/defaults.py", line 23, in server_error
t = loader.get_template(template_name) # You need to create a
500.html template.

  File "/home/thangappan/Non-Technical/Python/lib/python2.4/site-
packages/django/template/loader.py", line 81, in get_template
source, origin = find_template_source(template_name)

  File "/home/thangappan/Non-Technical/Python/lib/python2.4/site-
packages/django/template/loader.py", line 74, in find_template_source
raise TemplateDoesNotExist, name

TemplateDoesNotExist: 500.html



Why is there error occurring?

Please help me..?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Does anybody meet this strange Error

2010-03-09 Thread Forrest Liu
Thank you very much. trouble has been solved.

2010/3/9 rebus_ 

> On 9 March 2010 15:22, Forrest Liu  wrote:
> > Hi,
> > I am struck with this strange error message:
> > AttributeError at /products/
> >
> > 'function' object has no attribute 'objects'
> >
> > Request Method:GET
> > Request URL:http://127.0.0.1:8000/products/
> > Exception Type:AttributeError
> > Exception Value:
> >
> > 'function' object has no attribute 'objects'
> >
> > Exception Location:E:\workspace\biotech\biotech\..\biotech\bio\views.py
> in
> > product, line 35
> > my views.py:
> > def product(request):
> > products = product.objects.all().order_by('name')
> > return
> >
> object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)
> > my model.py:
> > class product(models.Model):
> > name = models.CharField(max_length=100)
> > description = models.TextField(blank=True)
> > def __unicode__(self):
> > return self.name
> >
> > and my index.html is :
> > {% for n in object_list %}
> > 
> > {{n.name}}
> > 
> > {% endfor %}
> > my Django version:1.1.1
> > python version: 2.6
> > Could you be so kind to give me some help,Thank you
> > --
> >
> > Best regards,
> > Forrest
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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.
> >
>
> Rename your model to Product with capital P.
>
> Right now when you say
>
> def product(request):
>products = product.objects.all().order_by('name')
>
> you are calling def product function instead of class product model.
>
>
> Try something like:
>
> def product(request):
>products = Product.objects.all().order_by('name')
>return
> object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)
>
> class Product(models.Model):
>name = models.CharField(max_length=100)
>description = models.TextField(blank=True)
>def __unicode__(self):
>return self.name
>
>
> Further reading:
>
> http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 

Best regards,
Forrest Liu

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 use pre-built HTML forms in Django

2010-03-09 Thread MMRUser
The problem I's having is that my HTML form depends upon lot of
external resources like javascript validation libraries and lots of
css on fields (and some may differ from each other), and I think that
I don't need to use re-usable templates because I just want to design
a one simple form so there's only one HTML file.Do you think that is
it ok to just ignore the Django's template system and get along with
the normal way.

On Mar 9, 2:32 pm, rebus_  wrote:
> On 9 March 2010 05:54, MMRUser  wrote:
>
>
>
> > Thanks another doubt,what about the css mappings class="field text
> > medium" do they also need to include in the class definition in
> > Django.
>
> > On Mar 9, 9:21 am, rebus_  wrote:
> >> On 9 March 2010 05:04, MMRUser  wrote:
>
> >> > I have an pre-built HTML form (means I design the HTML form
> >> > separately) and I need to reuse it with Django form class
> >> > (django.forms), So how do I incorporate my HTML form with Django form
> >> > class. for example
>
> >> > HTML:
>
> >> > 
> >> >  
> >> >  Username
> >> >  *
> >> >  
> >> >  
> >> >  
> >> >  
> >> > 
>
> >> > How do I map this HTML in to Django form definition, I know that it
> >> > can be done by modifying Django form fields according to this HTML.
> >> > But I guess it's a time consuming approach,so I would like to know
> >> > that is there any easy and time saving solutions for this issue.
>
> >> > Thanks.
>
> >> > --
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to 
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/django-users?hl=en.
>
> >> Well usually you first create a form in django and use its instance to
> >> generate the HTML.
>
> >> You can also write the HTML by yourself and all you need to be careful
> >> of is that name and id attributes of you inputs and input type are
> >> same as in the class you define.
>
> >> Your HTML corresponds to:
>
> >> class MyForm(forms.Form):
> >>    Field11 = forms.CharField(label="Username",  max_length=255)
>
> >> I highly recommend to first setup a form class then write HTML and
> >> making form fields have more sensible names then Field11.
>
> >> Also i suggest these links as further reading:
>
> >>http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangop...
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> No, CSS classes are not defined in form class (as far as i know).
>
> I would suggest using reusable form templates [1] and putting the CSS
> classes on field wrappers for example.
>
> This is what you are interested in:
>
> http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-temp...http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-...
>
> Which ever approach you decide to use is valid, but writing a bunch of
> your own HTML for forms takes more time but is also more customisable,
> on the other hand using shortcut methods such as "as_p" [1] or
> "as_table" [2] is faster but you have less control over the outputted
> HTML.
>
> [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
> [2]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 get current session user in models.py?

2010-03-09 Thread Aaron
How to get current session user in models.py?

I want to use a custom 'Manager' on a certain Model, which contains a
'user' field.
In this customized Manager, I want to filter records according to
whether the 'user' field equals to the current session username.

I know I can get 'user' from 'request' parameter, but the Manager is
located in the Meta part of a Model, how can I get the 'user' in this
case?

Can I achieve this without using other code in views?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Revised 1.2 release schedule

2010-03-09 Thread Russell Keith-Magee
Hi all,

Those of you that have been paying attention to the Django release
roadmap [1] will have noticed that the original estimated release date
for Django 1.2 final has passed, but we haven't actually made a final
release.

Although Django aims to follow a date-based release cycle, we won't
make a release that we know contains major bugs. Therefore, we need to
push back the final release date for Django 1.2.

There are currently 120 bugs logged against the 1.2 milestone. Many of
these bugs are minor or longstanding errors. Over the next few days,
the core team will be examining this ticket list, leaving only the
tickets that:

* reveal a significant flaw in a feature added during the 1.2 cycle, or
* have the potential to cause catastrophic data loss.

Any bug that doesn't meet one of these criteria will be taken off the
1.2 milestone. We won't forget about these issues -- they'll still be
in Trac, and we'll address them in a later release.

We're sensitive to the fact that during the Django 1.2 release cycle,
we haven't paid as much attention to bugs and smaller features as we
have done during previous releases. To address this, we're considering
making Django 1.3 a "feature light" release -- that is, we will spend
more time focussing on little features and long standing bugs, rather
than adding lots of big features like we have done with Django 1.2.
Once 1.2 lands, we'll have some more details about our exact plans for
the 1.3 cycle.

Until then, we'll try to blog every week to give you a status update,
letting you know how many tickets remain, any problems we  foresee,
and to provide an updated estimate of the 1.2 final delivery date.

So: there are 120 tickets remaining, but many of these will be bumped
from the final release. It's difficult to know exactly how much work
is left before we do the final ticket cull, but our first-cut revised
estimate for an RC1 release around March 22, with a final release
around March 29. We'll give you another update next week.

As always, any assistance preparing, reviewing or testing patches is
most welcome; the more help we get, the sooner we can release. If you
want to help out,check out the 1.2 todo list [2], find something that
sounds interesting and dig in!

[1] http://code.djangoproject.com/wiki/Version1.2Roadmap
[2] 
http://code.djangoproject.com/query?status=new=assigned=reopened=component=1.2=priority

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Choosing a desired database from a list of SQLite databases

2010-03-09 Thread Harsha Reddy
Hi All,

I have a requirement, which I am trying to come up with a proof of
concept using Django.
The requirement is:

I upload a zip file containing -

  archive.zip:
/db/scenario1.db
/db/scenario2.db
/db/scenario3.db
/db/scenario4.db

On the server unpack the zip file.. read the file objects extracted
from the zip file (shallow)
and send the list to the view for display in a list box.

When the user select a pirtucular db (say /db/scenario3.db).
The application should use the database to display the results present
in the selected database.
___

To accomplish the above requirement I have created a model to
communicate to the database which is able to talk to a single database
(whose name is specified in the settings.py).

To achieve the requirement mentioned about I am planning to
programatically update the value of datatype: DATABASES = {'default':
{ 'NAME': ''}}, to the value that is selected by the user.

My Question:

Exactly in which layer I should place the logic of switching the
databases so that Model is aware of the database being select and that
it has to communicate with?

Advice Please.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Django server side ajax vallidation

2010-03-09 Thread MMRUser
Hi,

Recently I'm trying to implement a simple Django application that
include one server side AJAX validation, it's a simple form input
field (username). I have used a pre-built in line AJAX validation
mechanism which uses jQuery. So the code goes like this

HTML snippet



Username:




The server side code snippet (embedded in to a php script)

/* RECEIVE VALUE */
$validateValue=$_POST['validateValue'];
$validateId=$_POST['validateId'];
$validateError=$_POST['validateError'];

/* RETURN VALUE */
$arrayToJs = array();
$arrayToJs[0] = $validateId;
$arrayToJs[1] = $validateError;

if($validateValue =="testname"){// validate??
$arrayToJs[2] = "true"; // RETURN TRUE
echo
'{"jsonValidateReturn":'.json_encode($arrayToJs).'}';  //
RETURN ARRAY WITH success
}else{
for($x=0;$x<100;$x++){
if($x == 99){
$arrayToJs[2] = "false";
echo
'{"jsonValidateReturn":'.json_encode($arrayToJs).'}';  // RETURN
ARRAY WITH ERROR
}
}

}

So I have some questions to ask from you people

How do I get the user name from the input field in to the back end?(in
order to use in Django environment)

Do I need to get JSON support in Python?

I think the server side script snippet already does a big part
(passing the value to the backend as a JSON object) but I want to know
how to use this in my Python code,and this is my first time using
jQuery and I do need to use this same exact validation library. Your
valuable corporation is expected.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: more than 1 foreign key

2010-03-09 Thread rebus_
On 9 March 2010 13:30, knight  wrote:
> I have the following models: http://slexy.org/view/s20T8yOiKZ.
> When I try to click add button for worlds in admin page it shows me
> the following error:
>  has more than 1 ForeignKey
> to .
> I think it's something to do with inline.
> What can it be?
>
> Regards, Arshavski Alexander.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-model

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



more than 1 foreign key

2010-03-09 Thread knight
I have the following models: http://slexy.org/view/s20T8yOiKZ.
When I try to click add button for worlds in admin page it shows me
the following error:
 has more than 1 ForeignKey
to .
I think it's something to do with inline.
What can it be?

Regards, Arshavski Alexander.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Does anybody meet this strange Error

2010-03-09 Thread rebus_
On 9 March 2010 15:22, Forrest Liu  wrote:
> Hi,
> I am struck with this strange error message:
> AttributeError at /products/
>
> 'function' object has no attribute 'objects'
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/products/
> Exception Type:AttributeError
> Exception Value:
>
> 'function' object has no attribute 'objects'
>
> Exception Location:E:\workspace\biotech\biotech\..\biotech\bio\views.py in
> product, line 35
> my views.py:
> def product(request):
>     products = product.objects.all().order_by('name')
>     return
> object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)
> my model.py:
> class product(models.Model):
>     name = models.CharField(max_length=100)
>     description = models.TextField(blank=True)
>     def __unicode__(self):
>         return self.name
>
> and my index.html is :
> {% for n in object_list %}
> 
> {{n.name}}
> 
> {% endfor %}
> my Django version:1.1.1
> python version: 2.6
> Could you be so kind to give me some help,Thank you
> --
>
> Best regards,
> Forrest
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>

Rename your model to Product with capital P.

Right now when you say

def product(request):
products = product.objects.all().order_by('name')

you are calling def product function instead of class product model.


Try something like:

def product(request):
products = Product.objects.all().order_by('name')
return 
object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)

class Product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True)
def __unicode__(self):
return self.name


Further reading:

http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 works django

2010-03-09 Thread Masklinn
On 9 Mar 2010, at 15:30 , serek wrote:
> 
> Hi
> 
> I am quite new in django. Could you explain me how django process
> incoming request?
> I have coded in php before, and there every request was like script
> starts again (read config file, connect db, etc). in django it seems
> different ;) and I do not understand it well yet. I will thankfull for
> information, links, etc.
> 
> Thanks in advance.

http://www.b-list.org/weblog/2006/jun/13/how-django-processes-request/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: radio on admin

2010-03-09 Thread gustavo
Anyone please!?

On 8 mar, 13:36, gustavo  wrote:
> Sure Daniel,
>
> I have the admin showing only the "tipo"s label, not the choices!
>
> On 8 mar, 13:23, Daniel Roseman  wrote:
>
> > On Mar 8, 4:12 pm, gustavo  wrote:
>
> > > Hello folks,
>
> > > I am having a hard time trying to use a radio button field on admin.
>
> > > I am using:
>
> > > tipo = models.IntegerField(
> > >                                max_length=1,
> > >                                choices = IMAGEM_TIPOS_CHOICES,
> > >                                )
>
> > > where IMAGEM_TIPOS_CHOICES is a list of tuples.
>
> > > Any light please?
>
> > > Thanks a lot!
>
> > And what is your problem? What is happening? What should be happening?
> > What error are you getting? Give us some clues here.
> > --
> > 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-us...@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 use pre-built HTML forms in Django

2010-03-09 Thread rebus_
On 9 March 2010 15:22, MMRUser  wrote:
> The problem I's having is that my HTML form depends upon lot of
> external resources like javascript validation libraries and lots of
> css on fields (and some may differ from each other), and I think that
> I don't need to use re-usable templates because I just want to design
> a one simple form so there's only one HTML file.Do you think that is
> it ok to just ignore the Django's template system and get along with
> the normal way.
>
> On Mar 9, 2:32 pm, rebus_  wrote:
>> On 9 March 2010 05:54, MMRUser  wrote:
>>
>>
>>
>> > Thanks another doubt,what about the css mappings class="field text
>> > medium" do they also need to include in the class definition in
>> > Django.
>>
>> > On Mar 9, 9:21 am, rebus_  wrote:
>> >> On 9 March 2010 05:04, MMRUser  wrote:
>>
>> >> > I have an pre-built HTML form (means I design the HTML form
>> >> > separately) and I need to reuse it with Django form class
>> >> > (django.forms), So how do I incorporate my HTML form with Django form
>> >> > class. for example
>>
>> >> > HTML:
>>
>> >> > 
>> >> >  
>> >> >  Username
>> >> >  *
>> >> >  
>> >> >  
>> >> >  
>> >> >  
>> >> > 
>>
>> >> > How do I map this HTML in to Django form definition, I know that it
>> >> > can be done by modifying Django form fields according to this HTML.
>> >> > But I guess it's a time consuming approach,so I would like to know
>> >> > that is there any easy and time saving solutions for this issue.
>>
>> >> > Thanks.
>>
>> >> > --
>> >> > You received this message because you are subscribed to the Google 
>> >> > Groups "Django users" group.
>> >> > To post to this group, send email to django-us...@googlegroups.com.
>> >> > To unsubscribe from this group, send email to 
>> >> > django-users+unsubscr...@googlegroups.com.
>> >> > For more options, visit this group 
>> >> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> >> Well usually you first create a form in django and use its instance to
>> >> generate the HTML.
>>
>> >> You can also write the HTML by yourself and all you need to be careful
>> >> of is that name and id attributes of you inputs and input type are
>> >> same as in the class you define.
>>
>> >> Your HTML corresponds to:
>>
>> >> class MyForm(forms.Form):
>> >>    Field11 = forms.CharField(label="Username",  max_length=255)
>>
>> >> I highly recommend to first setup a form class then write HTML and
>> >> making form fields have more sensible names then Field11.
>>
>> >> Also i suggest these links as further reading:
>>
>> >>http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangop...
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> No, CSS classes are not defined in form class (as far as i know).
>>
>> I would suggest using reusable form templates [1] and putting the CSS
>> classes on field wrappers for example.
>>
>> This is what you are interested in:
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-temp...http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-...
>>
>> Which ever approach you decide to use is valid, but writing a bunch of
>> your own HTML for forms takes more time but is also more customisable,
>> on the other hand using shortcut methods such as "as_p" [1] or
>> "as_table" [2] is faster but you have less control over the outputted
>> HTML.
>>
>> [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
>> [2]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

Well, if you need a high level of customization you can write your own
HTML for forms of course.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Register multiple models to show in admin page

2010-03-09 Thread rebus_
On 9 March 2010 10:31, andrew_scfc  wrote:
> Hi,
>
> I'm new to using Django and have come across some redundancy in my
> implementation that I would like to irradicate.
>
> I have defined several models in the models.py file as normal. I would
> like to register all of my models to be available via the admin
> interface. Currently I need to register models one by one in the
> admin.py as show below:
>
> from mysite.models import model1, model2, model3, model4, model5
> from django.contrib import admin
>
> admin.site.register(model1)
> admin.site.register(model2)
> admin.site.register(model3)
> admin.site.register(model4)
> admin.site.register(model5)
>
>
> Is it possible to just register all models? Perhaps get hold of a
> collection containing all the models. I am quite new to python so I
> may have missed something quite simple, if so, I apologise.
>
> Cheers
> Andy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

models = [model1, model2, model3, model4, model5]
admin.site.register(models)

This should work i think.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 use pre-built HTML forms in Django

2010-03-09 Thread rebus_
On 9 March 2010 05:54, MMRUser  wrote:
> Thanks another doubt,what about the css mappings class="field text
> medium" do they also need to include in the class definition in
> Django.
>
> On Mar 9, 9:21 am, rebus_  wrote:
>> On 9 March 2010 05:04, MMRUser  wrote:
>>
>>
>>
>> > I have an pre-built HTML form (means I design the HTML form
>> > separately) and I need to reuse it with Django form class
>> > (django.forms), So how do I incorporate my HTML form with Django form
>> > class. for example
>>
>> > HTML:
>>
>> > 
>> >  
>> >  Username
>> >  *
>> >  
>> >  
>> >  
>> >  
>> > 
>>
>> > How do I map this HTML in to Django form definition, I know that it
>> > can be done by modifying Django form fields according to this HTML.
>> > But I guess it's a time consuming approach,so I would like to know
>> > that is there any easy and time saving solutions for this issue.
>>
>> > Thanks.
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> Well usually you first create a form in django and use its instance to
>> generate the HTML.
>>
>> You can also write the HTML by yourself and all you need to be careful
>> of is that name and id attributes of you inputs and input type are
>> same as in the class you define.
>>
>> Your HTML corresponds to:
>>
>> class MyForm(forms.Form):
>>    Field11 = forms.CharField(label="Username",  max_length=255)
>>
>> I highly recommend to first setup a form class then write HTML and
>> making form fields have more sensible names then Field11.
>>
>> Also i suggest these links as further reading:
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangoproject.com/en/dev/ref/forms/api/http://docs.djangoproject.com/en/dev/ref/forms/fields/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

No, CSS classes are not defined in form class (as far as i know).

I would suggest using reusable form templates [1] and putting the CSS
classes on field wrappers for example.

This is what you are interested in:

http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-templates
http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-using-a-template

Which ever approach you decide to use is valid, but writing a bunch of
your own HTML for forms takes more time but is also more customisable,
on the other hand using shortcut methods such as "as_p" [1] or
"as_table" [2] is faster but you have less control over the outputted
HTML.

[1] http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
[2] http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: admin rows aren't ordered as expected

2010-03-09 Thread Wim Feijen
OK Thanks! That explains a lot.

Wim

On Mar 8, 2:54 pm, derek  wrote:
> On Mar 8, 2:46 pm, Wim Feijen  wrote:
>
>
>
>
>
> > Hello,
>
> > In my admin interface, the data isn't ordered as expected. What I get
> > is:
> > Provincie/Land   Type
> > Limburg     Provincie
> > Groningen  Provincie
> > Utrecht      Provincie
> > etc.
> > which clearly isn't alphabetical order, while I do specify that
> > provinces should be ordered that way. In my python manage.py shell the
> > provinces are ordered alphabetically. What could be wrong?
>
> > admin.py:
> > class ProvinceAdmin(admin.ModelAdmin):
> >     list_display = ('name', 'type')
> >     actions = None
>
> > admin.site.register(Province, ProvinceAdmin)
>
> > models.py:
> > class Province(models.Model):
> >     TYPES = (
> >         ('c', 'Land'),
> >         ('p', 'Provincie'),
> >     )
> >     name = models.CharField(max_length=200, verbose_name="Provincie/
> > Land")
> >     type = models.CharField(max_length=1, choices=TYPES, default='c')
>
> >     def __unicode__(self):
> >         return self.name
>
> >     class Meta:
> >         ordering = ('-type', 'name',)
> >         verbose_name = 'Provincie/Land'
> >         verbose_name_plural = 'Provincies/Landen'
>
> > For the record, I am using django trunk revision 12295 .
>
> > - Wim
>
> The Django 
> documentation:http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
> mentions that ... "Regardless of how many fields are in ordering, the
> admin site uses only the first field."
>
> """
> Minor observation:  shouldn't the format be
>     ordering = [-type', 'name',]
> """
>
> Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Testing if a file has changed while saving the class

2010-03-09 Thread Xavier Ordoquy
Hi,

I have a class with an image field.
Every time the image is changed, I need to resize the image to several formats.
At the moment, I do that every time the class which contains the image is saved.
However, I'd like to improve that a bit and only resize whenever the image has 
changed.

Is there any way to do that easily with Django 1.1 ?

Regards,
Xavier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: modify date in django twitter app

2010-03-09 Thread het.oosten
I figured it out finally.

For anybody who is interested. I have this setup for showing multiple
tweets:

settings.py:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS

TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS + (
"wieskamp.verkoop.context_processors.latest_tweet",
)

TWITTER_USER = "username"
TWITTER_TIMEOUT = 3600

This context_processor:
import datetime
import time
from django.conf import settings
from django.core.cache import cache
import twitter

def latest_tweet( request ):
tweet = cache.get( 'tweet' )

if tweet:
return {"tweet": tweet}

tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
count=3 )
for s in tweet:
s.date =
datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S
+ %Y" )[0:6]))
cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )

return {"tweet": tweet}

And this in my template:
{% if tweet %}
{% for x in tweet %}
{{ x.text|urlize}} 
{{ x.date|date:"d/m/Y" }}
{% endfor %}
{% endif %}

Thanks for the help and hints :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.